Rock Paper Scissor. How to make the Bomb code work


#1

I have completed the rock paper scissors game and now I am trying to add the bomb.
but the choice of “bomb” is breaking the game. Can someone tell me why?

I have not made user input a function because “prompt” does not seem to be working for me in this exercise window.

var userInput = “bomb”;
userInput = userInput.toLowerCase();

function getComputerChoice(){
var randomNumber= Math.floor(Math.random()*3);

switch(randomNumber){
case 0:
return “rock”;
break;
case 1:
return “paper”;
break;
case 2:
return “scissors”;
break;
default:
return “error”;
}
}
function determineWinner(userChoice,computerChoice){
if(userChoice === computerChoice){
return “Tie Game”;
}
if(userChoice === “rock”){
if(computerChoice === “paper”){
return “computer wins”;
} else {
return “User Wins”;
}
}
if(userChoice === “paper”){
if(computerChoice ===“scissors”){
return “computer wins”;
} else {
return “User wins”;
}
}
if(userchoice === “scissors”){
if(computerChoice === “rock”){
return “computer wins”;
} else {
return “User wins”;
}
}
if (userChoice === ‘bomb’) {
return ‘User Wins’;
}
}

function playGame(){
var userChoice = userInput;
var computerChoice = getComputerChoice();
console.log("You Threw: " + userChoice);
console.log("The computer threw: "+ computerChoice);
console.log( determineWinner(userChoice,computerChoice));
}

playGame();


#2

I have completed the rock paper scissors game but the addition of the bomb choice is breaking my game.
Can someone tell me why?
Note: I’ve seen other commenters use a function and prompt to get the user’s choice.
prompt did not seem to work so i’ve kept userInput at one declared value.
is this a problem for the bomb?

var userInput = "bomb";
userInput = userInput.toLowerCase();

function getComputerChoice(){
 var randomNumber= Math.floor(Math.random()*3);

switch(randomNumber){
  case 0: 
    return "rock";
    break;
  case 1:
    return "paper";
    break;
  case 2:
    return "scissors";
    break;
  default:
    return "error";
  }
}
function determineWinner(userChoice,computerChoice){
  if(userChoice === computerChoice){
  return "Tie Game";
 }
  if(userChoice === "rock"){
    if(computerChoice === "paper"){
      return "computer wins";
    } else {
      return "User Wins";
    }
   }
  if(userChoice === "paper"){
    if(computerChoice ==="scissors"){
      return "computer wins";
    } else {
      return "User wins";
    }
   }
  if(userchoice === "scissors"){
    if(computerChoice === "rock"){
      return "computer wins";
    } else {
      return "User wins";
    }
   }
    if (userChoice === 'bomb') {
    return 'User Wins';
  }
}

function playGame(){
  var userChoice = userInput;
  var computerChoice = getComputerChoice();
  console.log("You Threw: " + userChoice);
  console.log("The computer threw: "+ computerChoice);
console.log( determineWinner(userChoice,computerChoice));
}

playGame();


#3

Maybe you have a look at the usage of