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.
Day 2: Conditional Statements: Switch
Day 2: Conditional Statements: Switch
Sort by
recency
|
363 Discussions
|
Please Login in order to post a comment
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
function getLetter(s) { let letter; // Write your code here let sOne = "aeiou"; let sTwo = "bcdfg"; let sThree = "hjklm";
}
function getLetters(s){ let letter; switch(true){ case /[aeiou]/i.test(s[0]): return letter = "A"; case /[bcdfg]/i.test(s[0]): return letter = "B"; case /[hjklm]/i.test(s[0]): return letter = "C"; case /[aeiou]/i.test(s[0]): return letter = "A";