Rock, paper, scissors number 11


#1

/*User Choice*/

function getUserChoice() {
var userInput = prompt('Choose wisely');
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb') {
return userInput;
} else {
console.log('Invalid choice');
}
}
/*Computer Choice*/

function getComputerChoice() {
var compChoice = Math.floor(Math.random() *3);
if (compChoice === 0) {
return 'rock';
}
else if (compChoice === 1) {
return 'paper';
}
else if (compChoice === 2) {
return 'scissors';
}
}
/*Who won?*/

function determineWinner(userChoice, computerChoice) {
if (userChoice === computerChoice) {
return 'The game is a tie';
} if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'The computer won!';
} else {
return 'You won!';
}
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!';
}
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'The computer won!';
} if (userChoice === 'bomb') {
return 'You win!';
}
}
function playGame() {
var userChoice = getUserChoice();
var computerChoice = getComputerChoice();
console.log('computerChoice:' + computerChoice,'userChoice:' + userChoice);
console.log(determineWinner(userChoice, computerChoice));

}

playGame();

this is my code so far... how do i put in 11.
Make this game better by adding a secret cheat code. If a user types in 'bomb' as their choice, then make sure they win, no matter what.the instructions:

what would my code look like after this?


#2

You'd check the user's choice and if it's bomb the user wins, regardless of the computer's choice


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.