JavaScript bootcamp · Lab 13

Count the vowels

easyStrings10 minLesson: String Methods

Read the question, write JavaScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read one word and log how many vowels (a, e, i, o, u) it contains.

Count both cases — lowercase the word first so you only check one set.

Input. One line: a word.

Output. One integer: the vowel count.

Examples

Example 1 — o, a, i.
Input
Programming
Output
3
Example 2 — y does not count here.
Input
sky
Output
0
Hint
  1. Loop over the characters with for (const c of word).
  2. "aeiou".includes(c) is a compact vowel test.
Show correct code

Peek only after you have tried. You can still Check your own version.

const word = readLine().trim().toLowerCase();
let count = 0;
for (const c of word) if ("aeiou".includes(c)) count++;
console.log(count);
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.