Hi all
I need some help, I’m not sure what’s wrong with my code.
It looks like its not running the first if statement
if(input[inputText] === vowel[vowels]) but I’m not too sure.
The code runs but it runs everything and not just the vowels
Code
var input = “turpentine and turtles”;
let vowels = [“a”, “e”, “i”, “o”, “u”];
var resultArray = ;
// the above is just for variable
for (let inputText = 0 ; inputText < input.length ; inputText++){
for (let vowel = 0 ; vowel < vowels.length ; vowel++){
if(input[inputText] === vowel[vowels]){
}
if (input[inputText] === "e") {
resultArray.push("ee");
}else if (input[inputText] === "u") {
resultArray.push("uu");
} else {
resultArray.push(input[inputText])
}
}
}
console.log(resultArray.join('').toUpperCase());
Hello @eugenegovender, welcome to the forums! Notice how you’ve closed the first if
block without putting any code in it?
if(input[inputText] === vowel[vowels]){
}
^
This closes the "if" block
Hi @ codeneutrino
thank you for the response.
I originally had a nest if function but the code does run when I do that.
var input = “turpentine and turtles”;
let vowels = ["a", "e", "i", "o", "u"];
var resultArray = [];
// the above is just for variable
for (let inputText = 0 ; inputText < input.length ; inputText++){
for (let vowel = 0 ; vowel < vowels.length ; vowel++){
if(input[inputText] === vowel[vowels]){
if (input[inputText] === "e") {
resultArray.push("ee");
}else if (input[inputText] === "u") {
resultArray.push("uu");
} else {
resultArray.push(input[inputText])
}
}
}
}
console.log(resultArray.join('').toUpperCase());
the output is then blank.
Notice how the iterable variable (the one that increments as the loop runs) is declared as vowel
, here:
for (let vowel = 0 ; vowel < vowels.length ; vowel++){
^
Should you be checking for the index of vowels
in vowel
here? Isn’t vowels
an array?
if(input[inputText] === vowel[vowels]){
^ ^
\ /
Are these variables in the right order?
2 Likes