Learn Form Validation by Building a Calorie Counter - Step 21

Tell us what’s happening:

What’s wrong in for array loop ?

function cleanInputString(str) {
  const strArray = str.split('');
  const cleanStrArray = [];
  for(let i=0;i<strArray.length-1;i++){

  }

Console Output:

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 21

hello! @TTEOTM

I am sorry, I am wrong!

it is length not length-1

2 Likes

I dn’t understand …it already has i++ in :

for(let i=0;i<strArray.length-1;i++){

  }

Hi @TTEOTM

As @Jyothsna13 pointed out to iterate though the array use the length method.

length - 1 is used to find the last item of an array.

The reason your code may not be working may be because the function is missing a closing curly bracket.

Happy coding

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