const userChoice = userInput => {
userInput = userInput.toLowerCase();
if (
userInput === “rock” ||
userInput === “scissors” ||
userInput === “paper” ||
userInput === ‘bomb’
) {
return userInput;
} else {
console.log(“Error, please type: rock, paper or scissors.”);
}
if (userChoice == ‘bomb’) {
return ‘Congratulations, you won!’
}
}
const computerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return “rock”;
case 1:
return “paper”;
case 2:
return “scissors”;
}
};
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return “This game is a tie!”;
};
if (userChoice === “rock”) {
if (computerChoice === “paper”) {
return “sorry, computer won!”;
} else {
return “Congratulations, you won!”;
}
}
if (userChoice === “paper”) {
if (computerChoice === “scissors”) {
return “Sorry, computer won!”;
} else {
return “Congratulations, you won!”;
}
}
if (userChoice === “scissors”) {
if (computerChoice === “paper”) {
return “Sorry, computer won!”;
} else {
return “Congratulations, you won!”;
}
if(userChoice === ‘bomb’) {
return ‘Congratulations, you won!’;
}
};
const playGame = playGame = () => {
const userChoice = getUserChoice(‘paper’);
const computerChoice = getComputerChoice();
console.log('You threw: ’ + userChoice);
console.log('The computer threw: ’ + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
};
playGame()
// task 7
// when the text is not colored normally that is a sign of what is wrong.
// if you see a red ending bracket it is most likely an extra one you do not need.
// you do not need to have parenthesis around the return
// task 8
// we already covered what happens in a tie in the last task. in this task we say if the player chooses rock, than there are only two other scenarios. one in which the computer picks paper, in which case, the comptuer wins. and the ohter where the computer picks scissors, and the player wins. the else statement is for scissors and doesn’t need to be fully written out because it is the only option left.