摘自Syntaxerror:“意外令牌”) |如果在JavaScript中使用其他语句

发布于 2025-02-06 08:55:59 字数 1344 浏览 1 评论 0原文

如果其他条件有语法错误,看来我可以帮忙吗?控制台吐出此链接{/home/ccuser/workspace/javascript_101_unit_3_v2/rockpaperscissors.js:38 }); }和错误指向“)”

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

此刻的回忆 2025-02-13 08:55:59

您定义一个外壳,但是您缺少最终}

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

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";
  }
}
生生漫 2025-02-13 08:55:59

您只是错过了destryinwinner(...)方法的最后/关闭}

这就是您的代码外观!

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

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";
  }
}
烟沫凡尘 2025-02-13 08:55:59

尝试以下操作:
ComputerChoice的末尾){,添加,看看是否有效!

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文