How do I deal with SyntaxError: Unexpected token: Typo
How do I deal with SyntaxError: Unexpected token: Typo
我想知道我的错误逻辑,应该怎么写呢,求教。谢谢
这是问题:
编写一个名为“findShortestOfThreeWords”的函数。
给定 3 个字符串,“findShortestOfThreeWords”returns 是给定字符串中最短的一个。
如果有联系,它应该 return 参数列表中的第一个单词。
我得到的错误:
/home/runner/Module-1/index.js:21
}esle{
^
语法错误:意外的标记 '{'
我的代码:
function findShortestOfThreeWords(word1, word2, word3){
//if word1 was less than or equal word2
//return word1
//else
//return word2
//if word1 is less than or equal word3
//return word1
//esle
//return word3
//if word2 is less than or equal word3
//return word2
//else
//return word3
if(word1.length <= word2.length){
return word1;
}else{
return word2;
}if(word1.length <= word3.length){
return word1;
}esle{
return word3;
}if(word2.length <= word3.length ){
return word2;
}else{
return word3;
}
}
var output = findShortestOfThreeWords('a', 'two', 'three');
console.log(output); // --> 'a'
将esle
更改为else
function findShortestOfThreeWords(word1, word2, word3){
//if word1 was less than or equal word2
//return word1
//else
//return word2
//if word1 is less than or equal word3
//return word1
//esle
//return word3
//if word2 is less than or equal word3
//return word2
//else
//return word3
if(word1.length <= word2.length){
return word1;
}else{
return word2;
}if(word1.length <= word3.length){
return word1;
}else{
return word3;
}if(word2.length <= word3.length ){
return word2;
}else{
return word3;
}
}
var output = findShortestOfThreeWords('a', 'two', 'three');
console.log(output); // --> 'a'
您的代码中似乎有错别字:
esle{
return word3;
尝试将其更改为其他
我想知道我的错误逻辑,应该怎么写呢,求教。谢谢
这是问题:
编写一个名为“findShortestOfThreeWords”的函数。 给定 3 个字符串,“findShortestOfThreeWords”returns 是给定字符串中最短的一个。 如果有联系,它应该 return 参数列表中的第一个单词。
我得到的错误:
/home/runner/Module-1/index.js:21 }esle{ ^ 语法错误:意外的标记 '{'
我的代码:
function findShortestOfThreeWords(word1, word2, word3){
//if word1 was less than or equal word2
//return word1
//else
//return word2
//if word1 is less than or equal word3
//return word1
//esle
//return word3
//if word2 is less than or equal word3
//return word2
//else
//return word3
if(word1.length <= word2.length){
return word1;
}else{
return word2;
}if(word1.length <= word3.length){
return word1;
}esle{
return word3;
}if(word2.length <= word3.length ){
return word2;
}else{
return word3;
}
}
var output = findShortestOfThreeWords('a', 'two', 'three');
console.log(output); // --> 'a'
将esle
更改为else
function findShortestOfThreeWords(word1, word2, word3){
//if word1 was less than or equal word2
//return word1
//else
//return word2
//if word1 is less than or equal word3
//return word1
//esle
//return word3
//if word2 is less than or equal word3
//return word2
//else
//return word3
if(word1.length <= word2.length){
return word1;
}else{
return word2;
}if(word1.length <= word3.length){
return word1;
}else{
return word3;
}if(word2.length <= word3.length ){
return word2;
}else{
return word3;
}
}
var output = findShortestOfThreeWords('a', 'two', 'three');
console.log(output); // --> 'a'
您的代码中似乎有错别字: esle{ return word3;
尝试将其更改为其他