Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我在代码中做错了什么?它显示意外的令牌错误_Javascript - Fatal编程技术网

Javascript 我在代码中做错了什么?它显示意外的令牌错误

Javascript 我在代码中做错了什么?它显示意外的令牌错误,javascript,Javascript,我的代码显示了一个带有右括号的意外令牌错误。这是什么意思 我尝试过添加和删除括号和花括号 const getUserChoice = userInput => {userInput = userInput.toLowerCase(); if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') { return userInput; } else { console.log('Err

我的代码显示了一个带有右括号的意外令牌错误。这是什么意思

我尝试过添加和删除括号和花括号

const getUserChoice = userInput => {userInput = userInput.toLowerCase();
if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
    return userInput;
} else {
  console.log('Error! That\'s not part of the game!');
}

它不应该记录任何内容,而是记录错误。

代码中有语法错误。您忘记添加缺少的end}大括号

您使用了:

const getUserChoice = userInput => {userInput = userInput.toLowerCase();
而不是:

const getUserChoice = userInput => {userInput = userInput.toLowerCase();}
你能看到你用过的例子中缺少的大括号吗


提示:遵循@grumbler\u chester的建议。使用代码编辑器或IDE突出显示语法

正确地输入您的代码,您将看到为什么末尾缺少一个花括号。请考虑使用A。请使用J/S语法突出显示或LIDTE/CHECKE来验证源文件中的语法在执行之前。我尝试过,它给了我一个错误,即USER输入不是。defined@FireFlyCrisis您会发现代码经常有多个错误,您必须修复一个错误才能到达另一个错误。这个答案是正确的。用户输入未定义是您必须解决的另一个问题-直到纠正第一个错误后才看到,因为解释器无法解析代码。@FireFlyCrisis请不要删除或更改您的注释。正如paul所说:在开发软件时,您经常会遇到错误。请记住:作为开发人员,这是一个正常的尝试错误。我相信我已经解决了这个问题,我添加了另一行并在末尾放了一个花括号,它没有显示错误。谢谢你的帮助:@FireFlyCrisis但是你收到我们的消息了吗?作为一名开发人员意味着什么?如何处理stackoverflow中的评论?