Instructions
Create a function grade that takes a score (0-100) and returns a letter grade:
- 90-100: "A"
- 80-89: "B"
- 70-79: "C"
- 60-69: "D"
- Below 60: "F"
Hints:
- Use if/elsif/else or case statement
- Check from highest to lowest
- You can use ranges with case: when 90..100
Your Code
def grade(score) case score when 90..100 then "A" when 80..89 then "B" when 70..79 then "C" when 60..69 then "D" else "F" end end
RSpec.describe "grade" do
it "returns A for 95" do
expect(grade(95)).to eq("A")
end
it "returns A for 90" do
expect(grade(90)).to eq("A")
end
it "returns B for 85" do
expect(grade(85)).to eq("B")
end
it "returns C for 75" do
expect(grade(75)).to eq("C")
end
it "returns D for 65" do
expect(grade(65)).to eq("D")
end
it "returns F for 55" do
expect(grade(55)).to eq("F")
end
end
Results
Click "Run Tests" to see results