My brain is melting, any help would be nice


#1

I am on the new version of Learn JavaScript Section 3, Freeform project Rock, Paper, Scissors. After moving thru it, it kicks back a reference error userChoise is not defined. I think I have been looking at the code for to long because I can't seem to find anything wrong with it. Any help and I would bless your entire blood line.:slight_smile:

This is my code so far.

function getUserChoice() {
  var userInput = prompt('Choose Rock, Paper, or Scissors?');
  userInput = userInput.toLowerCase();
  
  if (userInput === 'Rock' || userInput === 'Paper' ||  userInput === 'Scissors') {
    return userInput;
    } 
  else {
      console.log('test error!');
    }
}

function getComputerChoice() {
  var randomNumber = Math.floor(Math.random()* 3);
  
  switch (randomNumber) {
  case 0:
    return 'Rock';
  case 1:
    return 'Paper';
  case 2:
    return 'Scissors';    
                      }
  
}
function determineWinner() {
  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 === 'scissors') {
    return 'The computer won!';
  } else {
    return 'You won!';
  }
}
  
 if (userChoice === 'scissors') {
  if (computerChoice === 'rock') {
    return 'The computer won!';
  } else {
    return 'You won!';
  }
} 
}
function playGame() {
  var userChoice = getUserChoice();
  var computerChoice = getComputerChoice();
  console.log('You threw: ' + userChoice);
  console.log('The computer threw: ' + computerChoice);
  console.log(determineWinner(userChoice, computerChoice));
}

playGame();

#2

you know that string comparison is case-sensitive?

so here you convert to lowercase:

userInput = userInput.toLowerCase();

So know if the user enters Rock it gets converted to rock, how can then this condition:

if (userInput === 'Rock'

how can this ever be true? change it:

if (userInput === 'rock'

the same hopefully goes without saying for paper and scissors


#3

function getUserChoice() {
var userInput = prompt('Choose rock, paper, or scissors?');
userInput = userInput.toLowerCase();

if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
return userInput;
}
else {
console.log('test error!');
}
}

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

switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}

}
function determineWinner() {
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 === 'scissors') {
return 'The computer won!';
} else {
return 'You won!';
}
}

if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!';
}
}
}
function playGame() {
var userChoice = getUserChoice();
var computerChoice = getComputerChoice();
console.log('You threw: ' + userChoice);
console.log('The computer threw: ' + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}

playGame();


#4

yes? what is it?


#5

I think the problem is that your determineWinner brackets are empty, should be:

function determineWinner(userChoice, computerChoice) {
blablabla...
}

At least thats the way I did it and mine works