We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
function getLetter(s) {
let letter;
let a = ["a","e","i","o","u"];
let b = ["b","c", "d", "f","g"];
let c = ["h", "j", "k", "l", "m"];
// // Write your code here
// return a.includes(s[0])
// if(a.includes(s[0])){
// return "A"
// }else{
// return "no"
// }
let firstChar = s[0]
switch (true) {
case a.find(item => item === firstChar) !== undefined:
letter = "A";
break;
case b.includes(firstChar):
letter = "B";
break;
case c.includes(firstChar):
letter = "C";
break;
default:
letter = "D";
}
return letter;
}
commented code is for understanding
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 2: Conditional Statements: Switch
You are viewing a single comment's thread. Return to all comments →
function getLetter(s) { let letter; let a = ["a","e","i","o","u"]; let b = ["b","c", "d", "f","g"]; let c = ["h", "j", "k", "l", "m"];
switch (true) { case a.find(item => item === firstChar) !== undefined: letter = "A"; break; case b.includes(firstChar): letter = "B"; break; case c.includes(firstChar): letter = "C"; break; default: letter = "D"; }
}
commented code is for understanding