Objective
In this challenge, we learn about switch statements. Check out the attached tutorial for more details.
Task
Complete the getLetter(s) function in the editor. It has one parameter: a string, , consisting of lowercase English alphabetic letters (i.e., a through z). It must return A, B, C, or D depending on the following criteria:
- If the first character in string is in the set , then return
A. - If the first character in string is in the set , then return
B. - If the first character in string is in the set , then return
C. - If the first character in string is in the set , then return
D.
Hint: You can get the letter at some index in using the syntax s[i] or s.charAt(i).
Input Format
Stub code in the editor reads a single string denoting from stdin.
Constraints
- , where is the length of .
- String contains lowercase English alphabetic letters (i.e.,
athroughz) only.
Output Format
Return either A, B, C, or D according to the criteria given above.
Sample Input 0
adfgt
Sample Output 0
A
Explanation 0
The first character of string is a. Because the given criteria stipulate that we print A any time the first character is in , we return A as our answer.
Solution
function getLetter(s) {
let letter;
// Write your code here
switch(s[0]){
case 'a': letter="A";break;
case 'e': letter="A"; break;
case 'i': letter="A";break;
case 'o': letter="A";break;
case 'u': letter="A";break;
case 'b': letter="B";break;
case 'c': letter="B";break;
case 'd': letter="B";break;
case 'f':letter="B";break;
case 'g': letter="B";break;
case 'h':letter="C";break;
case 'j':letter="C";break;
case 'k':letter="C";break;
case 'l':letter="C";break;
case 'm':letter="C";break;
case 'n':letter="D";break;
case 'p':letter="D";break;
case 'q':letter="D";break;
case 'r':letter="D";break;
case 's':letter="D";break;
case 't':letter="D";break;
case 'v':letter="D";break;
case 'w':letter="D";break;
case 'x':letter="D";break;
case 'y':letter="D";break;
case 'z':letter="D";break;
}
return letter;
}
Comments
Post a Comment