"use strict";
function vovelsAndConstants(s) {
let vowels = new Array();
let constants = new Array();
for (let a = 0; a < s.length; a++) {
//console.log(s[a]);
if (s[a] === "a" || "e" || "i" || "o" || "u") {
console.log(s[a]);
}
}
}
vovelsAndConstants("sosisvesalam");
I can't understand why or operator here doesn't work It all makes sense to me. It outputs all chars instead of vowels
s[a] === "a" || "e"---->s[a] === "a" || s[a] === "e"...includes.if (s[a] === "a" || "e" || "i" || "o" || "u")meansif((s[a] === "a") || Boolean("e") || Boolean("i") || Boolean("o") || Boolean("u"))which is basicallyif((s[a] === "a") || true || true || true || true)or simplyif(true). Take a look at Operator Precedencelet vowels = s.match(/[aeiou]/gi);let consonants = s.match(/[^aeiou]/gi);or betterlet consonants = s.match(/(?=[a-z])[^aeiou]/gi);