-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
16 lines (15 loc) · 725 Bytes
/
Copy pathscript.js
File metadata and controls
16 lines (15 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
document.addEventListener('DOMContentLoaded', () => {
const randomNumber = Math.floor(Math.random() * 100) + 1;
const submitButton = document.getElementById('submitGuess');
const resultDisplay = document.getElementById('result');
submitButton.addEventListener('click', () => {
const userGuess = parseInt(document.getElementById('guess').value, 10);
if (userGuess === randomNumber) {
resultDisplay.textContent = 'Congratulations! You guessed it right!';
} else if (userGuess < randomNumber) {
resultDisplay.textContent = 'Too low. Try again!';
} else {
resultDisplay.textContent = 'Too high. Try again!';
}
});
});