Having complications with adding totals which results in a different answer..keep on getting wrong answer..tried many ways but stil incorrect

var totalCost = (50-callCost * call.length) + (50-dataCost * data.length) + (50-smsCost * sms.length )

What is your goal here? Give me a complete sentence

1 Like

A friend of yours started playing WordCrush a really addictive word puzzle game on Facebook and he asked you to write him some functions to help him solve some word puzzles.

Given a sentence write some functions (function names in brackets) that can:

Find the longest word (longestWord);
find the shortest word (shortestWord);
find the sum of all the word lengths, in a sentence. (wordLengths).

hello fellow coders…have a slight problem with getting a longer word from a sentence…it keeps on resulting in an empty array…

var longestWord = function(string) {
//var wordLength = longestWord.length
var longWord =
var sentence = string.split(’,’);
for (var i = 0; i < sentence.length; i++) {
if (sentence[i] < longWord) {
//wordLength = sentence.length
longWord.push(sentence[i]);
}
}

return longWord;

}
var longer = longestWord(‘I applied to an open collaboration at workshop 17’);
console.log(longer);

var longestWord = function(string) {
//var wordLength = longestWord.length
var longWord = []; // Why an Array? Change that
var sentence = string.split(','); // Why do you wanna split where a comma is?
// Every word is seperated by a whitespace. Change that

for (var i = 0; i < sentence.length; i++) {
       if (sentence[i] < longWord) { // what do you compare here? A string could not be smaller as an other string only the length of it could. And you wanna know is the new word greater as the word in the var long word
              //wordLength = sentence.length
              longWord.push(sentence[i]); // dont push to an Array its not needed.
       }
}

return longWord;
}
var longer = longestWord('I applied to an open collaboration at workshop 17');
console.log(longer);