-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
27 lines (23 loc) · 822 Bytes
/
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
let randomNumber = Math.floor(Math.random() * 11);
// let randomNumber = 9;
let btn = document.getElementById("button");
let text = document.getElementById("entry");
let output = document.getElementById("result");
let guessOutput = document.getElementById("text");
let restart = document.getElementById("reset");
let correctGuess = randomNumber;
btn.addEventListener("click", () => {
if (text.value == "") {
return undefined;
}
if (text.value == correctGuess) {
output.innerHTML = `<p><strong>Your guess is correct: ${text.value}.</strong></p>`;
guessOutput.innerHTML = `<p><strong>Guess: ${randomNumber}</strong></p>`;
} else {
output.innerHTML = `<p><strong>Wrong guess..</strong></p>`;
}
});
restart.addEventListener("click", (e) => {
e.preventDefault();
window.location.reload();
});