JavaScript does not have a not
keyword. Instead, it has a !
for whenever you want to use not.
JS's in
is NOT the same as python's in
. JS uses it for indexes, and if you want the character at the index, you should use of
.
I have also made some minor tweaks here and there like not using var and removing the continue statements.
function removeVowels(string) {
// Instead of using var here, use let and const.
let newString = '';
const vowels = ['a','e','i','o','u'];
// Loop through every character of string
for (const char of string) {
// Instead of the continue that you used, you can just simply check if the vowels array includes the specific character.
if (!vowels.includes(char.toLowerCase())) {
// This just appends the character to the new string variable
newString += char;
}
}
return newString;
}
console.log(removeVowels('This string will not have any vowels in it.'));