-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (23 loc) · 752 Bytes
/
app.js
File metadata and controls
26 lines (23 loc) · 752 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
//Declare
let attempts = 0;
let randomNumber = Math.floor(Math.random() * 100 + 1);
const guess = document.getElementById("guess");
const sumbit = document.getElementById("submit");
const hint = document.getElementById("hint");
const attemptsText = document.getElementById("attempts");
// Event listeners
sumbit.addEventListener("click", checkGuess);
function checkGuess() {
const userValue = Number(guess.value);
attempts++;
// Conditionals
if ( userValue === randomNumber) {
hint.textContent
"Congratulation , you guessed it!"
} else if (userValue < randomNumber) {
hint.textContent = "Too low! Try again.";
} else {
hint.textContent = "Too high! Try again.";
}
attemptsText.textContent = "Attempts: " + attempts;
}