Rock, Paper, Scissors (I have no idea what I am doing.)


#1

I am really not sure how I got this far, but I am stuck. I appreciate any help!

Rock, Paper, Scissors

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:42
else (computerChoice === ‘rock’)
^^^^
SyntaxError: Unexpected token else
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

The Code:



var userInput = 'Rock';
	userInput = userInput.toLowerCase();

function getComputerChoice(){
  Math.Floor(Math.random() * 3);
  
  switch (randomNumber){
    case 0:
      return 'rock';
    case 1:
      return 'paper';
    case 2: 
      return 'scissors';
                      }
  
  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 === 'paper') {
  if (computerChoice === 'rock'){
    return 'You won!';
  }
 else (computerChoice === 'scissors')
   return 'The computer Won!';
 
  
}
 
  if (userChoice === 'scissors'){
    if (computerChoice === 'paper'){
      return 'You win!';
     else  (computerChoice === 'rock')
       return 'The computer 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

else can’t have a condition, given its everything else.


#3

thank you I will change it and give it a shot…


#4

Okay I changed somethings.

I am now getting this error:
/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:59
playGame();
^

ReferenceError: playGame is not defined
at Object. (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:59:1)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3

my new code is :

var userInput = 'rock';
	userInput = userInput.toLowerCase();

function getComputerChoice(){
  Math.Floor(Math.random() * 3);
  
  switch (randomNumber){
    case 0:
      return 'rock';
    case 1:
      return 'paper';
    case 2: 
      return 'scissors';
                      }
  
  if (userChoice === computerChoice) {
    return 'The game is a tie!';
      }
  if (userChoice === 'rock'){
    if (computerChoice === 'paper'){
      return 'The computer won!';
    }
    if (computerChoice === 'scissors') {
      return 'You won!';
    }
  }
  

if (userChoice === 'paper') {
  if (computerChoice === 'rock'){
    return 'You won!';
  }
 	if (computerChoice === 'scissors') {
   return 'The computer Won!';
 }
  
}
 
  if (userChoice === 'scissors'){
   if (computerChoice === 'paper'){
      return 'You win!';
     if (computerChoice === 'rock') {
       return 'The computer 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();

#5

you nested your playGame function inside your getComputerChoice function. your playGame function should be outside/after getComputerChoice function


#6

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