Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
get number then get n names and count each word vowel char JS

The goal is to get a number n from the user then get n words from the user and show each word vowel char count in the console. But it doesn't get the counts correct. #JS #vowel

let n = prompt('Enter the number:');
let wordList = [];
let vowelCounter = [];
let stringWordList = '';

for (i = 0; i < n; i++) {
    wordList.push(prompt((i + 1) + 'Word #'))
}
debugger
function getVowels(str) {
    var m = str.toString().match(/[aeiou]/gi);
    return m === null ? 0 : m.length;
};
/*function vowelCount(str) {
    return str.toString().replace(/[^aeiou]/gi, "").length;*/
};
for (i = 0; i < n; i++) {
    stringWordList = wordList[i].toString
    vowelCounter.push(getVowels(stringWordList));
    console.log(wordList[i] + ':' + vowelCounter[i]);
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

remove the carrot symbol from the regex and try:

function getVowels(str) {
    var m = str.toString().match(/[aeiou]/gi);
    return m === null ? 0 : m.length;
};

console.log(getVowels("testme123"));

about 4 years ago · Juan Pablo Isaza Report

0

After removing your carrot symbol, you need to clean a bit your code (was not running on JSFIDDLE):

let n = prompt('Enter the number:');
let wordList = [];
let vowelCounter = [];
let stringWordList = '';

for (i = 0; i < n; i++) {
    wordList.push(prompt((i + 1) + 'Word #'))
}
//debugger
function getVowels(myString) {
    var m = myString.match(/[aeiou]/gi);
    return m === null ? 0 : m.length;
}
/*function vowelCount(str) {
    return str.toString().replace(/[^aeiou]/gi, "").length;*/
for (i = 0; i < n; i++) {
    stringWordList = wordList[i].toString();
    vowelCounter.push(getVowels(stringWordList));
    console.log(wordList[i] + ':' + vowelCounter[i]);
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!