Hi guys, I am currently at this challenge and I feel like I’ve got the idea of how to complete it but there’s a little problem.
Whenever I run this code I get a TypeError {message: “Cannot assign to read only property ‘length’ of string ‘The’”}. Is there a workaround for this? What is the reason for this?
Here’s my code:
function findLongestWord(str) {
var arrayedString = str.split(" ");
var lengthOfLongestString = 0;
for(var i = 0; i < arrayedString.length; i++) {
if(arrayedString[i].length > lengthOfLongestString) {
arrayedString[i].length = lengthOfLongestString;
}
}
return lengthOfLongestString;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
Any help would be appreciated!