not immediately clear but its an alternative... :-D
function getGrade (s1, s2, s3) { const pos = (function rank(avg, grade, i) { if (avg / grade > 1 || i > 4) return i return rank(avg, grade-10, ++i) })((s1+s2+s3)/3, 90, 0) return String.fromCharCode(65 + pos) }
function getGrade (s1, s2, s3) {let avg = (s1 + s2 + s3) / 3;if (avg >= 90) {return "A"}else if (avg >= 80) {return "B"}else if (avg >= 70) {return "C"}else if (avg >= 60) {return "D"}else {return "F"}- function getGrade (s1, s2, s3) {
- const pos = (function rank(avg, grade, i) {
- if (avg / grade > 1 || i > 4) return i
- return rank(avg, grade-10, ++i)
- })((s1+s2+s3)/3, 90, 0)
- return String.fromCharCode(65 + pos)
- }
const chai = require("chai"); const assert = chai.assert; const Test = require("@codewars/test-compat"); describe("Solution", function() { it("Hey! Good job!", function() { Test.assertEquals(getGrade(69, 94, 31), "D"); Test.assertEquals(getGrade(95, 89, 92), "A"); Test.assertEquals(getGrade(68, 91, 95), "B"); Test.assertEquals(getGrade(0, 65, 13), "F"); }); });
- const chai = require("chai");
- const assert = chai.assert;
- const Test = require("@codewars/test-compat");
- describe("Solution", function() {
- it("Hey! Good job!", function() {
- Test.assertEquals(getGrade(69, 94, 31), "D");
- Test.assertEquals(getGrade(95, 89, 92), "A");
- Test.assertEquals(getGrade(68, 91, 95), "B");
- Test.assertEquals(getGrade(0, 65, 13), "F");
- });
- });