Can i use something similar on the switch with node.js?
let = "aggsfg";
if (s[0] == "a" || s[0] == "e" || s[0] == "i" || s[0] == "o" || s[0] == "u") {
console.log("vogais");
} else if (s[0] == "b" || s[0] == "c" || s[0] == "d" || s[0] == "f" || s[0] == "g") {
console.log("consoantes1");
}
CodePudding user response:
let s = "aggsfg";
if ('aeiou'.includes(s[0].toLowerCase())) {
console.log("vogais");
} else if ('bcdfghjklmnpqrstvwxyz'.includes(s[0].toLowerCase())) {
console.log("consoantes1");
}
You had an error when declaring the variable s.
CodePudding user response:
Node does have a switch statement. See here.
CodePudding user response:
You can still compress your code using if
and includes
. But this is how you can do it with switch
let s = "aggsfg";
switch(s[0]) {
case "a" || "e" || "i" || "o" || "u":
console.log("vogais")
case "b" || "c" || "d" || "f" || "g":
console.log("consoantes1")
}