Number of vowels in the word entered

Tell us what’s happening:

This is my code,but it’s not giving the right result please help
Your code so far

function wordOperation() {
let word = “”;
word = prompt(“please enter a word”);

for(let i = 0; i < word.length; i++)
if (
word[i] === “a” ||
word[i] === “e” ||
word[i] === “i” ||
word[i] === “o” ||
word[i] === “u”
let vowels= word[i].length




Is the goal to log the # of vowels? Right now it is logging the length of the i-th character of the word string, which should always be 1 if typecasting is working, or some error value if not.

If what you mean by # of vowel is number of vowel yes that is what I want

Well, the let vowels… line is your problem.

That, and that crazy conditional. It doesn’t check for capital vowels “AEIOU” right now. You need toLowerCase(word) first.

Also, you should probably move the console.log statement out of the for loop and write in a variable that keeps track of the vowel count, like numVowels: Initialize to 0, and ++ it inside the conditional.

I don’t understand you maybe it’s because am still a beginner can you please explain better.Thanks

Is this for an FCC challenge?

no I am using it to learn js

I assume English isn’t your first language, so I’m going to forgive the insult of “explain better.”

You aren’t asking me to debug some random code you wrote, you are asking me to teach you how to code, which is a little much for this format, so I will point out all your mistakes and show you where you can learn to fix them:

  1. You aren’t checking for capitalized vowels “AIEOU”:
  2. You are using an ugly conditional to check for multiple possibilities. This is exactly why switch statements exist:
  3. You need to keep track of how many vowels you have encountered using a for loop to iterate through the characters in the string that prompt() returns:

Edit: accidentally submitted after only 2 points

okay,thans for your assistance

Sorry for firing off the last reply before I was done. The three links I gave you should help you solve the 3 main problems with your code.