0 : 0

🏆 make 5 points, take your choice! 💩

Fight !

		
let msg = document.getElementById('msg');
let rep = document.getElementById('rep');
let userScore = 0;
let computerScore = 0;
const user     = document.getElementById("user");// points
const computer = document.getElementById("computer");// points
const rock   = document.getElementById("rock");
const paper  = document.getElementById("paper");
const scisor = document.getElementById("scisor");


function getComputerChoice() {
	let choices = ["rock", "paper", "scisor"];
	let randomNum = Math.floor(Math.random() * 3);
			return choices[randomNum]; // 0, 1, 2
}


function myFunction() {
rock.addEventListener("click", () => {
game("rock");
});
paper.addEventListener("click", () => {
game("paper");
});
scisor.addEventListener("click", () => {
game("scisor");
});
}
myFunction();

function game(userChoice) {
	const computerChoice = getComputerChoice();

	console.log("User choice: " + userChoice);
	console.log("Computer choice: " + computerChoice);

	if (userChoice === "paper" && computerChoice === "rock") {
		
			userScore += 1;
			user.innerHTML = userScore;
			rep.innerHTML = `${userChoice} win on ${computerChoice}`;
	

		paper.classList.add('green');
		setTimeout(() => { paper.classList.remove('green'); }, 500);
	}

	else if (userChoice === "scisor" && computerChoice === "paper") {
		
			userScore += 1;
			user.innerHTML = userScore;
		rep.innerHTML = `${userChoice} win on ${computerChoice}`;

		scisor.classList.add('green');
		setTimeout(() => { scisor.classList.remove('green'); }, 500);		

	}
		
	else if (userChoice === "rock" && computerChoice === "scisor") {
			userScore += 1;
			user.innerHTML = userScore;
			rep.innerHTML = `${userChoice} win on ${computerChoice}`;

		rock.classList.add('green');
		setTimeout(() => { rock.classList.remove('green'); }, 500);		
	}
		
	else if (userChoice === "rock" && computerChoice === "rock") {
		userScore = userScore;
		computerScore = computerScore;
		rep.innerHTML = "Draw";

			rock.classList.add('white');
			setTimeout(() => { rock.classList.remove('white'); }, 500);	
	}
		
	else if (userChoice === "paper" && computerChoice === "paper") {
		userScore = userScore;
		computerScore = computerScore;
		rep.innerHTML = "Draw";

			paper.classList.add('white');
			setTimeout(() => { paper.classList.remove('white'); }, 500);	
	}		
		
	else if (userChoice === "scisor" && computerChoice === "scisor") {
		userScore = userScore;
		computerScore = computerScore;
		rep.innerHTML = "Draw";

			scisor.classList.add('white');
			setTimeout(() => { scisor.classList.remove('white'); }, 500);	
	}		
	
	else {
		computerScore += 1;
		computer.innerHTML = computerScore;
		rep.innerHTML = `${userChoice} lose on ${computerChoice}`;

		let arrLoose = [paper, scisor, rock];
		arrLoose.forEach((e) => {
		  	e.addEventListener('click', () => {
				e.classList.add('red');
				setTimeout(() => { e.classList.remove('red'); }, 500);
			});
		});	

	}


// Other Condition :
	if (userScore >= 5) {
		msg.innerHTML = `🏆🏆🏆You Win ${userScore} to ${computerScore} !!🏆🏆🏆`;
		document.body.style.background = "lightgreen";
		setTimeout(()=>{document.body.style.background = "#333";}, 150);
			rock.disabled   = true;		
			paper.disabled  = true;
			scisor.disabled = true;
			userScore = 0;
			computerScore = 0;
		setTimeout(() => {
			if (confirm("Good job, Play Again ?")) {
				rep.innerHTML = "Fight Again !";
				setTimeout(() => {rep.innerHTML = "Fight !";}, 3000);
			} else {
				rep.innerHTML = "Good bye";
				setTimeout(() => {rep.innerHTML = "Fight !";}, 3000);
						}
			msg.innerHTML = `🏆 make 5 points, take your choice! 💩`;
		}, 2500);

					user.innerHTML = userScore;
					computer.innerHTML = computerScore;

	}
	
	else if (computerScore >= 5) {
		msg.innerHTML = `💩💩💩You Looose ${userScore} to ${computerScore} !!💩💩💩`;
		document.body.style.background = "orangered";
		setTimeout(()=>{document.body.style.background = "#333";}, 150);
			rock.disabled   = true;		
			paper.disabled  = true;
			scisor.disabled = true;
			userScore = 0;
			computerScore = 0;
		setTimeout(() => {
			if (confirm("Try Again ???")) {
				rep.innerHTML = "Courage";
				setTimeout(() => {rep.innerHTML = "Fight !";}, 3000);
			} else {
				rep.innerHTML = "Looser !";
				setTimeout(() => {rep.innerHTML = "Fight !";}, 3000);
			}
			msg.innerHTML = `🏆 make 5 points, take your choice! 💩`;
		}, 2500);

					user.innerHTML = userScore;
					computer.innerHTML = computerScore;
	}

}
	
Tenzin
182