Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uncaught SyntaxError: "Unexpected token )" | If else statement in JavaScript

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";
  }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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";
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading