Recap - Grade Classifier
Part of the Logic & Flow section of Coddy's Ruby journey — lesson 42 of 56.
Combine multi-value case, ternary, and inline modifiers to classify exam scores in one short script.
Challenge
MediumRead a comma-separated list of integer scores from input. For each score, print one line:
<score>: <letter> (<status>)Where letter comes from a case on the score:
90..100→A80..89→B70..79→C60..69→D- anything else →
F
And status uses a ternary: passing when the score is at least 60, failing otherwise.
After the loop, print Top scorer: <score>: but only if the maximum score is 90 or higher (use an inline if).
For input 95,72,55,88, the output is:
95: A (passing)
72: C (passing)
55: F (failing)
88: B (passing)
Top scorer: 95Try it yourself
scores = gets.chomp.split(",").map(&:to_i)
# TODO: for each score print "<n>: <letter> (<status>)"
# TODO: print "Top scorer: <max>" only if max >= 90
All lessons in Logic & Flow
1Strings In Depth
String Methods OverviewString InterpolationIterating Over StringsSplit and JoinRecap - String Weaver4Blocks, Procs & Lambdas
What is a Block?do..end vs BracesThe yield KeywordBlock ParametersProcs and LambdasRecap - Custom Iterator7Hashes Part 2
Hash.new with DefaultsIterating HashesNested HashesMerging and TransformingRecap - Frequency Counter10Project - Student Records
Project OverviewAdd Student5Enumerable Powerhouse
Select and RejectChaining MapReduce / Injectcount, all?, any?, none?group_by and partitionsort_by, min_by, max_byRecap - Data Pipeline8Advanced Decision Making
Case with Classes & RegexMulti-value whenTernary OperatorInline if / unlessRecap - Grade Classifier