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: If-Else
Day 2: Conditional Statements: If-Else
Sort by
recency
|
201 Discussions
|
Please Login in order to post a comment
Another solution close to if else but much more clean code: function getGrade(score) { let grade; // Write your code here const ranges = [ { max: 5, grade: 'F' }, { max: 10, grade: 'E' }, { max: 15, grade: 'D' }, { max: 20, grade: 'C' }, { max: 25, grade: 'B' }, { max: 30, grade: 'A' } ]; for(const {max, grade} of ranges){ if (score <= max) return grade; }
}
Using Ternary Operator
function getGrade(score) { // Write your code here
}