+ 1

can somebody tell me what i am doing wrong???

function largestr(str){ string=[""]; str =str.split(" "); for (let i =0;i<str.length;i++){ if(str[i]>string.length){ return string.push(i); } return string } } var y =largestr("please make it work"); console.log(y);

24th Feb 2019, 9:27 PM
satya mallipeddi
satya mallipeddi - avatar
3 Réponses
+ 2
I'm not sure what you're looking for, but these are some potential issues: 1. string is an array of one element: "". string.length = 1. 2. You can't return string.push(i). The property .push adds a string to the end of an array. i isn't a string. If you're still not satisfied, tell me what you're looking for.
24th Feb 2019, 10:09 PM
yinhaodragon7
yinhaodragon7 - avatar
0
i am trying to print out the largest string ,Initially i use split to convert the string into array then i denote the length of the array then i try to add that largest string to the variable string. but some how as i am new to coading i am unable to write down my own logic
25th Feb 2019, 1:51 AM
satya mallipeddi
satya mallipeddi - avatar
0
https://code.sololearn.com/WP3E1dBUItkg/#js The variable longestWord is set to the first word. Then, a for loop checks each word to see if it is longer than the current longest word. If so, var longestWord is set to that word.
25th Feb 2019, 2:58 AM
yinhaodragon7
yinhaodragon7 - avatar