Add functionality for counting and resetting rounds
This commit is contained in:
parent
329920601b
commit
abfdbf97d7
1 changed files with 7 additions and 0 deletions
|
|
@ -2,11 +2,13 @@
|
||||||
let pScore = 0;
|
let pScore = 0;
|
||||||
let cScore = 0;
|
let cScore = 0;
|
||||||
let ps;
|
let ps;
|
||||||
|
let count = 0;
|
||||||
const buttons = document.querySelectorAll('button');
|
const buttons = document.querySelectorAll('button');
|
||||||
const msg = document.querySelector("#msg");
|
const msg = document.querySelector("#msg");
|
||||||
const score = document.querySelector("#score");
|
const score = document.querySelector("#score");
|
||||||
const player = document.querySelector("#player");
|
const player = document.querySelector("#player");
|
||||||
const computer = document.querySelector("#computer");
|
const computer = document.querySelector("#computer");
|
||||||
|
const rounds = document.querySelector("#rounds");
|
||||||
|
|
||||||
|
|
||||||
buttons.forEach((button) => {
|
buttons.forEach((button) => {
|
||||||
|
|
@ -80,6 +82,9 @@ function game() {
|
||||||
msg.textContent = "It's a tie! You both played " + cs + ".";
|
msg.textContent = "It's a tie! You both played " + cs + ".";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count ++;
|
||||||
|
rounds.textContent = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pScore === 5 || cScore === 5) {
|
if (pScore === 5 || cScore === 5) {
|
||||||
|
|
@ -109,7 +114,9 @@ function endGame() {
|
||||||
function resetGame() {
|
function resetGame() {
|
||||||
pScore = 0;
|
pScore = 0;
|
||||||
cScore = 0;
|
cScore = 0;
|
||||||
|
count = 0;
|
||||||
player.textContent = "0";
|
player.textContent = "0";
|
||||||
computer.textContent = "0";
|
computer.textContent = "0";
|
||||||
msg.textContent = "";
|
msg.textContent = "";
|
||||||
|
rounds.textContent = "";
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue