I am having trouble capturing the first “e” letter in my array.
My if loops are not doubling the first “e” in my input.
Can anyone tell me what I might be missing? Why isn’t my code doubling the first ‘e’
Here is my code:
let input = "elephant day i am shuffling and hustling";
let vowels = ["a", "e", "i", "o", "u"];
let resultArray = [];
for (let i = 0; i < input.length; i++) {
//console.log([i]);
if (input[i] === "e") {
resultArray.push(input[i]);
}
if (input[i] === "u") {
resultArray.push(input[i]);
for (let j = 0; j < vowels.length; j++) {
//console.log([j]);
if (input[i] === vowels[j]) {
// console.log(input[i]);
resultArray.push(input[i]);
//console.log(resultArray);
}
}
}
}
console.log(resultArray); //Prints: [ 'e', 'e', 'u', 'u', 'u', 'u']