0

I am a junior developer learning JS. Here is the piece of code I am practicing today.

I see the line " (var x=0; x < str1.length; x++) " almost every example I work on.

Can someone please explain what the mechanics are doing? Why do we always set a var equal to 0? What role does str1.length play in this line?

function vowel_count(str1) {
  var vowel_list = 'aeiouAEIOU';
  var vcount = 0;

  for (var x = 0; x < str1.length; x++){
    if (vowel_list.indexOf(str1[x]) !== -1)
    {
      vcount += 1;
    }

  }

  return vcount;

}

console.log(vowel_count("The quick black panther."));
tony_ysl
  • 1
  • 4

0 Answers0