I want to know the logic of my error and how should I write it instead, please. Thank You
This is the question:
Write a function called "findShortestOfThreeWords".
Given 3 strings, "findShortestOfThreeWords" returns the shortest of the given strings.
If there are ties, it should return the first word in the parameters list.
The Error I get:
/home/runner/Module-1/index.js:21
}esle{
^
SyntaxError: Unexpected token ‘{‘
my code:
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'
>Solution :
Change esle to 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'