JAVASCRIPT / STRINGS · STEP 1 OF 5
Count English vowels without losing repeats
Checking your account…
GUIDED PRACTICE
Count English vowels without losing repeats
Follow the current step, write the requested code and choose Run & check this step. Your own program carries forward.
Your code stays in one editor through every step. Word wrap is enabled.
Step 1 of 5
Define the counter function
This exercise counts a, e, i, o and u. Repeated vowels each count; y and accented letters are outside its scope.
Your task
In script.js, make the changes in the checklist. Keep the working code from earlier steps.
To pass this step:
- Define
function countVowels(str) { }.
Press the play button labeled Run & check this step below the editor to run your code and see your check results.
Your editor is opening.
Each step builds on the last. Finish the current step before opening the next one; your code stays with you.
This is one possible solution. Compare it with your own code; opening it does not replace your work or complete a step.
// Build your program one step at a time.
function countVowels(str) {}function countVowels(str) {
const vowels = "aeiou";
let count = 0;
}function countVowels(str) {
const vowels = "aeiou";
let count = 0;
for (let i = 0; i < str.length; i++) {
if (vowels.includes(str[i].toLowerCase())) {
count++;
}
}
}function countVowels(str) {
const vowels = "aeiou";
let count = 0;
for (let i = 0; i < str.length; i++) {
if (vowels.includes(str[i].toLowerCase())) {
count++;
}
}
return count;
}function countVowels(str) {
const vowels = "aeiou";
let count = 0;
for (let i = 0; i < str.length; i++) {
if (vowels.includes(str[i].toLowerCase())) {
count++;
}
}
return count;
}
console.log(countVowels("hello"));
console.log(countVowels("AEIOU"));
console.log(countVowels("rhythm"));Code and completed steps save in this browser when signed out. Sign in to save across devices.
Choose the copy to continue. Your account work will only be replaced if you choose this device.
Ready to checkRun the checks to see your results here.