samedi 16 janvier 2021

Javascript if statement or operator not working

"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

Aucun commentaire:

Enregistrer un commentaire