Rock paper error

Hello!

Complete newbie and working through the javascript section quite slowly. I keep encountering syntax errors when completing some of the javascript projects especially rock paper scissors. I even watched the walkthrough and ended up copying the code and still getting errors.

Just wondering if anyone has any insight into whether it is me being stupid or if there is something going on here. Below is a draft of the code but I have edited it so many times it probably has errors in it now.

Is there a way I can test JS using visual code editor? I am able to write code in there just not sure why it won’t run.

Any help most appreciated. Thank you in advance!

const getUserChoice = userInput => {
    userInput = userInput.toLowerCase();
if (userInput === 'scissors' || userInput === 'rock' || userInput ==='paper') {
    return userInput;
} else {
    console.log('error');
}
}
const getComputerChoice = () => {
  const randomNumber = Math.floor(Math.random() * 3);
  swtich (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 "congrats you won"; 
   }
}
}
if (userChoice === 'scissors'){
  if (computerChoice === 'rock')
  return "sorry computer won";
 } else {
   return "congrats you won"; 
 
};

const playGame = () => {
const userChoice = getUserChoice('paper');
const computerChoice = getComputerChoice();
console.log ('You threw:' + userChoice);
console.log ('Computer threw:' + computerChoice);
console.log (determineWinner(userChoice, computerChoice));

};

playGame()

The syntax error points to the right line?

here:

  swtich (randomNumber) {

notice how switch doesn’t have the same color in the editor as other keywords? Why could that be?

Oh god i’m such an idiot

thank you also for pointing this out, I think i also need some further understanding of this, cause I still get errors and swear when I fix one, another comes along.

const determineWinner = (userChoice, computerChoice); => {

I have fixed my capitalisation errors.

I could be wrong but have you tried removing the semi colon after the parameters?

and heave it like this instead

const determineWinner = (userChoice, computerChoice) => {

2 Likes

Hey! thanks for helping out and posting a reply. I seem to have it fixed now. Thank you for your help.