-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
35 lines (32 loc) · 1.3 KB
/
script.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
var msg1 = document.getElementById("message1");
var msg2 = document.getElementById("message2");
var msg3 = document.getElementById("message3");
var answer = Math.floor(Math.random()*100) + 1;
var no_of_guesses = 0;
var guessed_nums = [];
function play(){
var user_guess = document.getElementById("guess").value;
if(user_guess < 1 || user_guess > 100){
alert("Please enter a number between 1 and 100.");
}
else{
guessed_nums.push(user_guess);
no_of_guesses += 1;
if(user_guess < answer){
msg1.textContent = "Your guess is too low.";
msg2.textContent = "No. of guesses: " + no_of_guesses;
msg3.textContent = "Guessed numbers are: " + guessed_nums;
}
else if(user_guess > answer){
msg1.textContent = "Your guess is too high.";
msg2.textContent = "No. of guesses: " + no_of_guesses;
msg3.textContent = "Guessed numbers are: " + guessed_nums;
}
else if(user_guess == answer){
msg1.textContent = "Yippie You Win!";
msg2.textContent = "The number was: " + answer;
msg3.textContent = "You passed it in " + no_of_guesses + " guesses";
document.getElementById("my_btn").disabled = true;
}
}
}