hello, everybody.
i have a question.
i have finished the exercise with a else…if statement but codecademy suggest to do it with an OR operator in the if condition.
i started doing it out of curiosity but i dont know ho to finish the condition.
would be really happy if someone has an explanation.
Since all vowels need to be on the array at least once you could do something else like this in your inner loop:
if (character is a vowel) {
push the character to the result array
if (the character is 'e' OR the character is 'u') {
push the character to the result array again
}
}
Obviously this isn’t working code, just trying to explain the logic of a possible solution. This would let you eliminate the else you currently have. A key part of this solution is to push the character you’re working with instead of hardcoding specific values. Once you know it’s a vowel, then you can use input[i] as the value to push.
you don’t. There are two possible ways to go about this:
always add the vowel to resultArray, then check if vowel is e or u, if so, push the vowel again. This is the flow illustrated by @selectall:
if (character is a vowel) {
push the character to the result array
if (the character is 'e' OR the character is 'u') {
push the character to the result array again
}
}
the other flow is to use if/else like you currently do: