摘自Syntaxerror:“意外令牌”) |如果在JavaScript中使用其他语句
如果其他条件有语法错误,看来我可以帮忙吗?控制台吐出此链接{/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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您定义一个外壳,但是您缺少最终
}
You defining an enclosure, but you're missing the final
}
您只是错过了
destryinwinner(...)
方法的最后/关闭}
。这就是您的代码外观!
You are just missing the last/closing
}
for yourdeterminWinner(...)
method.This is how you code should look like!
尝试以下操作:
在
ComputerChoice的末尾){
,添加:
,看看是否有效!Try this:
At the end of
computerChoice){
, add:
and see if that works!