What is wrong with my code? It is not working and I even followed the video?

Welcome to the Get Help category!

This is where you can ask questions about your code. Some important things to remember when posting in this category :slight_smile:

  • Learn how to ask a good question and get a good answer!
  • Remember to include a link to the exercise you need help with!
  • If someone answers your question, please mark their response as a solution :white_check_mark:
  • Once you understand a new concept, come back and try to help someone else!
const getUserChoice = userInput => { userInput = userInput.toLowerCase(); if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){ return userInput; } else { console.log('Error!'); } } const getComputerChoice = () => { const randomNumber = Math.random(Math.floor() * 3); switch(randomNumber) { case 0: return 'rock'; case 1: return 'paper'; case 2: return 'scissors'; } }; //I keep getting undefined? //console.log(getComputerChoice()); const determineWinner = (userChoice, computerChoice) => { if(userChoice === computerChoice){ return 'Tie'; } if(userChoice === 'rock') { if(computerChoice === 'paper'){ return 'comp won'; } else { return 'you won'; } if(userChoice === 'paper'){ if(computerChoice === 'scissors') { return 'computer won'; } else { return 'you won'; } } if(userChoice === 'scissors') { if(computerChoice === 'rock') { return 'Computer won'; } else { return 'you won'; } } } //console.log(determineWinner('paper', 'scissors')); const playGame = () =>{ const userChoice = getUserChoice('rock'); const computerChoice = getComputerChoice(); console.log('You threw: ' + userChoice); console.log('The computer threw:' + computerChoice); console.log(determineWinner(userChoice, computerChoice)); }; playGame();

here:

 if(userChoice === 'rock') {
    if(computerChoice === 'paper'){
      return 'comp won';
    } else {
      return 'you won';
    }

your forgot a } to close this if statement.

As a result, the curly brackets in your program do not match up, that is problematic

1 Like