Skip to content

Commit

Permalink
made reset button work and restore the page
Browse files Browse the repository at this point in the history
  • Loading branch information
brandond98 committed Nov 14, 2020
1 parent 0f7a37f commit 1db35bd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const secretNumber = Math.trunc(Math.random() * 20) + 1;
let secretNumber = Math.trunc(Math.random() * 20) + 1;
let score = 20;
document.querySelector('.number').textContent = secretNumber;

document.querySelector('.check').addEventListener('click', function () {
const guess = Number(document.querySelector('.guess').value);
Expand All @@ -16,9 +15,9 @@ document.querySelector('.check').addEventListener('click', function () {
} else if (guess === secretNumber) {
document.querySelector('.message').textContent =
'You entered the correct number! 🎉';
document.querySelector('.number').textContent = secretNumber;

document.querySelector('body').style.backgroundColor = '#60b347';

document.querySelector('.number').style.width = '30rem';

// When the guess it too high
Expand All @@ -44,3 +43,14 @@ document.querySelector('.check').addEventListener('click', function () {
}
}
});

document.querySelector('.again').addEventListener('click', function () {
score = 20;
secretNumber = Math.trunc(Math.random() * 20) + 1;
document.querySelector('.score').textContent = score;
document.querySelector('.number').textContent = '?';
document.querySelector('.message').textContent = 'Start guessing...';
document.querySelector('.guess').value = '';
document.querySelector('body').style.backgroundColor = '#222';
document.querySelector('number').style.width = '15rem';
});

0 comments on commit 1db35bd

Please sign in to comment.