0

It seems my if else condition has a syntax error, can somebody help? The console spits out this link { /home/ccuser/workspace/javascript_101_Unit_3_v2/rockPaperScissors.js:38 }); } and an error points to the ")"

  userInput = userInput.toLowerCase();
  if (userInput !== "rock" && userInput !== "paper" && userInput !== "scissor") {
    console.log("Error");
  } else {
    return userInput;
  }
}

const getComputerChoice = () => {
  const randomNumber = Math.floor(Math.random() * 3);
  switch(randomNumber){
    case 0: return "scissor";
    break;
    case 1: return "rock";
    break;
    default: return "paper";
    break;
  }
}

const determinWinner = (userChoice, computerChoice) => {
  if(userChoice === computerChoice){
    return "Its a tie";
  } else if (userChoice === "rock" && computerChoice ==="scissor"){
    return "The user won";
  } else if (userChoice === "paper" && computerChoice ==="rock"){
    return "The user won";
  } else if (userChoice === "scissor" && computerChoice ==="paper"){
    return "The user won";
  } else if (userChoice === "rock" && computerChoice ==="paper"){
    return "The computer won";
  } else if (userChoice === "paper" && computerChoice ==="scissor"){
    return "The computer won";
  } else if (userChoice === "scissor" && computerChoice ==="rock"){
    return "The computer won";
  }
3
  • 1
    where is the unexpected token? (the error tells you the location) Commented Jun 10, 2022 at 18:14
  • Your ifs and else ifs are good, but you need to close your function! Commented Jun 10, 2022 at 18:16
  • Are you sure the code you pasted here is actually from rockPaperScissors.js mentioned in the beginning? Also, which line is line 38? Commented Jun 10, 2022 at 18:20

3 Answers 3

1

You defining an enclosure, but you're missing the final }

  const determinWinner = (userChoice, computerChoice) => {
  if(userChoice === computerChoice){
    return "Its a tie";
  } else if (userChoice === "rock" && computerChoice ==="scissor"){
    return "The user won";
  } else if (userChoice === "paper" && computerChoice ==="rock"){
    return "The user won";
  } else if (userChoice === "scissor" && computerChoice ==="paper"){
    return "The user won";
  } else if (userChoice === "rock" && computerChoice ==="paper"){
    return "The computer won";
  } else if (userChoice === "paper" && computerChoice ==="scissor"){
    return "The computer won";
  } else if (userChoice === "scissor" && computerChoice ==="rock"){
    return "The computer won";
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

What a rookie mistake. Thank you very much! :)
1

You are just missing the last/closing } for your determinWinner(...) method.

This is how you code should look like!

const determinWinner = (userChoice, computerChoice) => {
  if(userChoice === computerChoice){
    return "Its a tie";
  } else if (userChoice === "rock" && computerChoice ==="scissor"){
    return "The user won";
  } else if (userChoice === "paper" && computerChoice ==="rock"){
    return "The user won";
  } else if (userChoice === "scissor" && computerChoice ==="paper"){
    return "The user won";
  } else if (userChoice === "rock" && computerChoice ==="paper"){
    return "The computer won";
  } else if (userChoice === "paper" && computerChoice ==="scissor"){
    return "The computer won";
  } else if (userChoice === "scissor" && computerChoice ==="rock"){
    return "The computer won";
  }
}

Comments

-1

Try this: At the end of computerChoice){, add : and see if that works!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.