You are viewing a single comment's thread. Return to all comments →
New to JS, Try with Set().
function getLetter(s) { let letter; s = s.toLowerCase(); const groupA = new Set('aeiou'); const groupB = new Set('bcdfg'); const groupC = new Set('hjklm'); const groupD = new Set('npqrstvwxyz'); switch (true) { case groupA.has(s[0]): letter = 'A'; break; case groupB.has(s[0]): letter = 'B'; break; case groupC.has(s[0]): letter = 'C'; break; case groupD.has(s[0]): letter = 'D'; break; default: letter = "Enter valid letter"; break; } return letter; }
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 →
New to JS, Try with Set().