I cannot find the error in this simple issue of javascript programming in which I need to check how many times the letter "o" appears in the sentence

Asked

Viewed 49 times

-3

    var frase = "The Lord of The Rings";

    var letra = "o";

    function vezesLetraAparece(frase, letra) {
      var resultado = 0;
      var indice;

      for (indice = 0; indice < frase.lenght; indice++) {
       if (letra === frase[indice]) {
        resultado ++;
          }
       }
      return resultado;
    }

  • frase.lenght => frase.length - You wrote length wrong...

  • And also forgot to call the function! :-)

1 answer

0

"length" is spelled wrong.

And also not using the function elsewhere to display the result.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.