**So basically it ignores a word **
when i run the code with this sentence it stops at the index of ‘super-long’.
function findLongestWordLength(str) {
let mewStr = ;
let yourMom = ‘’
let biggestWord = ‘’;
for(let index = 0 ; index < str.length;index++){
if(str[index] !== ’ '){
yourMom += str[index];
}else{
mewStr.push(yourMom);
yourMom = ‘’
}
}
for(let i = 0 ; i < mewStr.length;i++){
if (mewStr[i].length > biggestWord.length){
biggestWord = mewStr[i];
}
}
return biggestWord;
}
console.log(findLongestWordLength(“What if we try a super-long word such as otorhinolaryngology”))**
function findLongestWordLength(str) {
let mewStr = [];
let yourMom = ''
let biggestWord = '';
for(let index = 0 ; index < str.length;index++){
if(str[index] !== ' '){
yourMom += str[index];
}else{
mewStr.push(yourMom);
yourMom = ''
}
}
for(let i = 0 ; i < newStr.length;i++){
if (mewStr[i].length > biggestWord.length){
biggestWord = newStr[i];
}
}
return biggestWord.length;
}
;console.log(findLongestWordLength("What if we try a super-long word such as otorhinolaryngology"))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Find the Longest Word in a String