const endingWordLength=target.split("").reverse();
let spellChecker;
let isEnding;
if(str.split(" ").length===1){
// which means the "str" is one word;
const newArr=str.split("");
spellChecker=newArr.reverse();
}else if(str.split(" ").length>1){
// Which means the "str" is more than one word;
const newArr=str.replaceAll(" ","").split("");
spellChecker=newArr.reverse();
}
for(let i=0;i<endingWordLength.length;i++){
if(spellChecker[i]===endingWordLength[i]){
isEnding=true;
}else{
isEnding=false
break;
}
}
return isEnding;
}
confirmEnding("Open sesame","sage");
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.