forked from TheNewStyles/hackerrank-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay2.ConditionalStatements.js
More file actions
90 lines (67 loc) · 1.91 KB
/
Day2.ConditionalStatements.js
File metadata and controls
90 lines (67 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Objective
// In this challenge, we learn about if-else statements. Check out the attached tutorial for more details.
// Task
// Complete the getGrade(score) function in the editor. It has one parameter: an integer, , denoting the number of points Julia earned on an exam. It must return the letter corresponding to her according to the following rules:
// If , then .
// If , then .
// If , then .
// If , then .
// If , then .
// If , then .
// Input Format
// Stub code in the editor reads a single integer denoting from stdin and passes it to the function.
// Constraints
// Output Format
// The function must return the value of (i.e., the letter grade) that Julia earned on the exam.
// Sample Input 0
// 11
// Sample Output 0
// D
// Explanation 0
// Because , it satisfies the condition (which corresponds to D). Thus, we return D as our answer.
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});
main();
});
function readLine() {
return inputString[currentLine++];
}
function getGrade(score) {
let grade;
// Write your code here
switch (true) {
case (score <= 5):
grade = "F";
break;
case (score <= 10):
grade = "E";
break;
case (score <= 15):
grade = "D";
break;
case (score <= 20):
grade = "C";
break;
case (score <= 25):
grade = "B";
break;
case (score <= 30):
grade = "A";
break;
}
return grade;
}
function main() {
const score = +(readLine());
console.log(getGrade(score));
}