charat javascript in swicth 1

charat javascript in swicth

function getLetter(s) {
  let letter;
  // Write your code here
  switch (true) {
    case "aeiou".includes(s[0]):
      letter = "A";
      break;
    case "bcdefg".includes(s[0]):
      letter = "B";
      break;
    case "hijklm".includes(s[0]):
      letter = "C";
      break;
    case "nopqrstuvwxyz".includes(s[0]):
      letter = "D";
      break;
  }
  return letter;
}

Here is what the above code is Doing:
1. We’re using a switch statement to check if the first letter of the string is included in the following strings:
“aeiou”, “bcdefg”, “hijklm”, “nopqrstuvwxyz”.
2. If the first letter of the string is included in the string “aeiou”, then we set the variable letter to “A”.
3. If the first letter of the string is included in the string “bcdefg”, then we set the variable letter to “B”.
4. If the first letter of the string is included in the string “hijklm”, then we set the variable letter to “C”.
5. If the first letter of the string is included in the string “nopqrstuvwxyz”, then we set the variable letter to “D”.
6. Finally, we return the variable letter.

Similar Posts