-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
22 lines (22 loc) · 839 Bytes
/
scripts.js
File metadata and controls
22 lines (22 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let gameResult = document.getElementById("gameResult");
let userInput = document.getElementById("userInput");
let randomNumber = Math.ceil(Math.random() * 100);
function checkGuess() {
let guessedNumber = parseInt(userInput.value);
if (guessedNumber > randomNumber) {
gameResult.textContent = "Too High! Try Again.";
gameResult.style.backgroundColor = "#1e217c";
}
else if (guessedNumber < randomNumber) {
gameResult.textContent = "Too Low! Try Again.";
gameResult.style.backgroundColor = "#1e217c";
}
else if (guessedNumber === randomNumber) {
gameResult.textContent = "Congratulations! You got it right.";
gameResult.style.backgroundColor = "green";
}
else {
gameResult.textContent = "Please provide a valid input.";
gameResult.style.backgroundColor = "#1e217c";
}
}