Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let lineOfWords = 'I wanna be useful like a kultivator)';
- let word = "";
- let maxWord = "";
- //Беремо по слову з рядка і добавляємо в масив. Зміни у 1-ій і 2-ій умові if
- for (let i = 0; i < lineOfWords.length; i++) {
- if ((lineOfWords.charCodeAt(i) >= 65 && lineOfWords.charCodeAt(i) <= 90) ||
- (lineOfWords.charCodeAt(i) >= 97 && lineOfWords.charCodeAt(i) <= 122)) {
- word += lineOfWords[i];
- }
- if (word.length > 0 && (i == lineOfWords.length - 1 || lineOfWords[i] == " ")) {
- if (maxWord.length < word.length) {
- maxWord = word;
- }
- word = "";
- }
- }
- console.log(maxWord);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement