Skip to content

Commit

Permalink
Update rps.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hetbhalani authored May 22, 2024
1 parent bb8d8ca commit 8b64309
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions rps.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ const playGame = (userChoice) => {
const compChoice = genCompChoice();
// console.log("Comp's Choice is:",compChoice);

if(userScore == 10 || compScore == 10){
return;
}

if (userChoice == compChoice) {
gameDraw();
return;

}
else {

Expand Down Expand Up @@ -52,15 +57,19 @@ const gameDraw = () => {
// console.log("It's a Draw");
msg.innerText = "It's a Draw!";
msg.style.backgroundColor = "black";

}

const showWinner = (userWin, userChoice, compChoice) => {
if (userWin) {
// console.log("You Won");
msg.innerText = `You Won. ${userChoice} beats ${compChoice}`;
msg.style.backgroundColor = "green";

if(userScore < 10 && compScore < 10){
userScore++;
uscore.innerText = userScore;
}

if (userScore == 10) {
const start = () => {
Expand All @@ -72,32 +81,85 @@ const showWinner = (userWin, userChoice, compChoice) => {

msg.innerText = "Hurray!!! You Won the Game!";
msg.style.backgroundColor = "green";
reset();
disable();
}

}
else {
// console.log("You Lost");
msg.innerText = `You Lost. ${compChoice} beats ${userChoice}`;
msg.style.backgroundColor = "red";

if(compScore < 10 && userScore < 10){
compScore++;
cscore.innerText = compScore;
}


if(compScore == 10){
msg.innerText = "You Lost the Game!";
msg.innerText = "Game Over!";
msg.style.backgroundColor = "darkred";
reset();
disable();

}
}
}

resetBTN.addEventListener("click", () => {
userScore = 0;
compScore = 0;
uscore.innerText = userScore;
cscore.innerText = compScore;
msg.innerText = "Play Again!";
msg.style.backgroundColor = "black";


const stop = () => {
setTimeout(function() {
confetti.stop()
}, 100);
};
stop();
enable();
})

const reset = () => {
setTimeout (() => {
userScore = 0;
compScore = 0;
uscore.innerText = userScore;
cscore.innerText = compScore;
msg.innerText = "Play Again!";
msg.style.backgroundColor = "black"

const stop = () => {
setTimeout(function() {
confetti.stop()
}, 100);
};
stop();
})
enable();

}, 5000);


}

const disable = () => {
choices.forEach((choice) => {
choice.disabled = true;
choice.style.opacity = 0.5;
});
// msg.innerText = "Gsme Over!"
// msg.style.backgroundColor = " yellow"
};

const enable = () =>{
choices.forEach((choice) => {
choice.disabled = false;
choice.style.opacity = 1;
// choice.style.backgroundColor = ""
});
}

0 comments on commit 8b64309

Please sign in to comment.