Skip to content

Commit

Permalink
Finish the project
Browse files Browse the repository at this point in the history
  • Loading branch information
ktorres63 committed Apr 9, 2024
1 parent d102e69 commit 42b24d2
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,44 @@ const compSel = document.querySelector("#computerSel");
const compScore = document.querySelector("#computerScore");
const resultUI = document.querySelector("#result");

const container = document.querySelector(".score");
const items = document.querySelectorAll(".link");
items.forEach((i) => {
i.addEventListener("click", chooseOption);
});

const btn = document.querySelector("button");
btn.addEventListener("click", () => location.reload());

function showResult(att) {
if (att === 5) {
if (playerScore > computerScore) {
resultUI.textContent = results[0];
} else if (computerScore > playerScore) {
resultUI.textContent = results[1];
} else {
resultUI.textContent = results[2];
}
}
}


function chooseOption(e) {
let user = e.target.id;
let computer = getComputerChoice();
let result = playRound(user, computer);
playRound(user, computer);
attempts++;

userSel.textContent = user.toUpperCase();
compSel.textContent = computer.toUpperCase();

userScore.textContent = playerScore;
compScore.textContent = computerScore;
attempts++;
if (attempts === 5) {
if (userScore > computerScore) {
resultUI.textContent = results[0];
} else if (computerScore > userScore) {
resultUI.textContent = results[1];
} else {
resultUI.textContent = results[2];
}
}
showResult(attempts);


}

const items = document.querySelectorAll(".link");
items.forEach((i) => {
i.addEventListener("click", chooseOption);
});


function getComputerChoice() {
let index = Math.floor(Math.random() * options.length);
Expand Down Expand Up @@ -69,6 +79,3 @@ function playRound(playSel, compSel) {
computerScore++;
}
}

const btn = document.querySelector("button");
btn.addEventListener("click", () => location.reload());

0 comments on commit 42b24d2

Please sign in to comment.