-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.js
More file actions
32 lines (29 loc) · 788 Bytes
/
Copy pathnew.js
File metadata and controls
32 lines (29 loc) · 788 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
const min = 1;
const max = 100;
const answer = Math.floor(Math.random() * (max - min + 1)) + min;
let attempt = 0;
let guess;
let running = true;
while(running){
guess = window.prompt(`Guess a number between ${min} - ${max}`);
guess = Number(guess);
if(isNaN(guess)){
window.alert('Enter a Valid Number');
}
else if(guess < min || guess > max){
window.alert('Enter a Valid Number');
}
else {
attempt++;
if(guess < answer){
window.alert('Too Low Try Again');
}
else if(guess > max){
window.alert('Too High Try Again');
}
else {
window.alert(`You are Correct! The answer was ${answer}. it took you ${attempt}`);
running = false;
}
}
}