-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (33 loc) · 1.06 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const MAX = 100
const MIN = 0
const ATTEMPTS_NUMBER = 10
const getPlayerName = () => {
const playerName = prompt("Who are you?", "Enter your Name");
// debugger
return playerName;
}
const playerName = getPlayerName();
const getRandomNumber = () => {
const randomNumber = Math.round(Math.random() * 100)
return randomNumber
}
const number = getRandomNumber();
console.log(playerName, number);
const game = (max, min, attNumber, randomNumber, name) => {
alert(`Hello, ${name} !
I made a number in the range from ${min} to ${max}.
You have ${attNumber} attempts to guess the hidden number`)
for (let i = 0; i < attNumber; i++) {
const playerAnswer = prompt("Your try")
if (playerAnswer > randomNumber) {
alert("My number less")
} else if (playerAnswer < randomNumber) {
alert("My number bigger")
} else {
alert("Your guess!")
return
}
}
alert(`${name}, you won for ${attNumber} !`)
}
game(MAX, MIN, ATTEMPTS_NUMBER, number, playerName);