Hello I've just started learning JS and currently doing tutorial project on loops, basically taking the phrase "coconut closet" and translating it into "whale talk" equivalent = oouoe
I've already learnt that the else block is optional where you can have an if
without an else
; but on my first try when not knowing this, I included an else
statement to the if
statement. This in turn, when run on the console it had no ouput. Here is the code in question below:
let input = "coconut closet";
const vowels = ["a", "e", "i", "o", "u"];
let resultArray = [];
for (let i = 0; i < input.length; i++) {
for (let j = 0; j < vowels.length; j++) {
if (input[i] === vowels[j]) {
resultArray.push(vowels[j]);
} else return;
}
}
let resultString = resultArray.join('')
console.log(resultString);
I've tried to look for an explanation but currently unable to find any, can someone please explain why my code has no output?
I've tried this both on codecademy's IDE and VS Node.