You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
Hey guys,
Just a quick question surrounding Whale Talk in Loops. I understand the flow and logic, but I’m kind of confused about one section, as shown below. Why is [i] in square brackets? It’s confusing because “i” is iterating through a string, not an array. What am I missing at this point? Appreciate some tips.
const input = "whales";
const vowels = ["a", "e", "i", "o", "u"];
let resultArray = [];
for (let i = 0; i < input.length; i++){
//console.log("i is "+ i);//
//i is 0
//i is 1
//i is 2
//i is 3
//i is 4
for (let z = 0; z < vowels.length; z++){
if (input[i] === vowels[z]){ <<<<<<<<<<<<<here
if (input[i] === "e") {
resultArray.push("ee")
}
else if (input[i] === "u"){
resultArray.push("uu");
}
else{
resultArray.push(input[i]);
}
}
}
}
console.log(resultArray.join("").toUpperCase());