-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (30 loc) · 811 Bytes
/
script.js
File metadata and controls
34 lines (30 loc) · 811 Bytes
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
const playerName = prompt("What's your name ?")
const random = Math.round(Math.floor(Math.random() * 100) + 1);
let answer = "";
let outOfRange;
console.log(random);
do {
outOfRange = 0;
answer = parseInt(prompt("Give me a integer number between 1 and 100"));
if (isNaN(answer)) {
alert("I said a number");
}
if (answer < 1 || answer > 100) {
alert("Out of range")
outOfRange = true;
}
if (answer > 1 || answer < 100) {
answer = answer
}
}
while (isNaN(answer) || outOfRange === true);
do {
if (answer < random) {
answer = parseInt(prompt("It is more"));
}
else if (answer > random) {
answer = parseInt(prompt("It is less"));
}
}
while (!isNaN(answer) && answer !== random);
alert(`Well done ! ${playerName}`);