Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda