Good morning!,everyone..having some difficulties adding total costs in a for loop statement

var totalPhoneBill = function(string){
var data = string.split(’, ');
var sms =
var call =
var smsCost = 0.65
var callCost = 2.75
for(var i = 0;i<data.length;i++){
var totalCost = smsCost.length * callCost.length;
return totalCost
totalPhoneBill(‘call, sms, call, sms, sms’)

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>


Replace this line with your code.

<do not remove the three backticks above>

Take a look at this line:

smsCost.length * callCost.length  

You wanna calculate the totalCost
How much calls did your customer (call.length) with the price of 2.75 (call)

Same for sms
How much sms send your customer (sms.length) with the price of 0.65 (sms)

var totalCost = (x*y) + (a*b);

What to we have? What do we want to do with it?

I thanks guys that was very helpful.but i actually got to the answer lol…
I tried several steps and suddenly i got to itvar totalCost = smsCost*‘3’ + callCost*‘2’;

More dynamic

var totalCost = (smsCost* sms.length) + (callCost*call.length);

yip thanks that worked…i have another complication if u don’t mind…need to find the longestWord and the wordsLength.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).

not sure how to approach this

Use split to split the string.
You need a for loop to loop threw the created array.
In the loop put a if statement that compares the longest word length (stored in the first round from your loop)) with the actual word in the array :slight_smile:

var longestWord = function(string){
var data = string.split(’,’)
var longestWord = [collaboration]
for(var i = 0;i < data.length;i++){
if(data[i] = longestWord.length){

hi! its me again lol…need to subtract this (callCost * call.length) + (dataCost * data.length) + (smsCost * sms.length)
from 50… if anyone could please help…sorry for being so disturbing…how should i structure that

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.