Today's challenge is to write a function that accepts three integer values, calculates the mean, then returns the letter value associated with that grade. If the mean of those three integers ends in a number greater than five, append a plus sign to the letter grade. If it is less than five, append a minus sign.
Numerical Score Letter Grade 90 <= score <= 100 'A' 80 <= score < 90 'B' 70 <= score < 80 'C' 60 <= score < 70 'D' 0 <= score < 60 'F'
Examples:
grade(64, 55, 92)
=> C-
(70.3)
grade(99, 89, 93)
=> A-
(93.6)
grade(33, 99, 95)
=> C+
(75.6)
Happy coding!
This challenge was inspired by CodeWars user danleavitt0. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (19)
CSS
This will only work on Safari because, for some forsaken reason, Safari is the only browser that supports min() and max() at the moment. Which is funny considering that normally it is the other way around 🤷♂️
This can be represented as a decision machine with different ranges for different grades. Then the idea would be to have an element to which we pass the three grades as CSS variables (all integers or it will fail), calculate the z-index to set which element should be visible. I would need to double check the logic, I think it's correct. Also, I think the code can be simplified.
Here is the code running. Remember it will only work on Safari:
Too much ternary operators...
You could use something like that:
Not tested but I believe it would work in JavaScript.
I've Started to write a c# answer only to find out I'm going the exact same route as your answer...
Here's mine:
Gist: gist.github.com/kerrishotts/559154...
Nice Js!
Rust:
Python
Clojure (my new adventure):
Elm
Tests
Here's my type-level implementation in haskell:
My first stab at writing something other than "Hello World!" in golang:
This is my quick python solution