- Read Tutorial
- Watch Guide Video
- Complete the Exercise
Summary
Build a program that keeps track of a baseball team's score on an inning by inning basis along with totaling up the total runs.
Exercise Description
Build a Ruby class that works like a scoreboard for a 9 inning game. This means that the class should start a game where every inning has 0 runs and as the game goes on, runs can be added to runs, which also changes the total.
Example Game
team = Scoreboard.new('Astros') team.score # => {"Astros"=>{1=>0, 2=>0, 3=>0, 4=>0, 5=>0, 6=>0, 7=>0, 8=>0, 9=>0}} team.add_run inning: 3 team.add_run inning: 3 team.add_run inning: 5 team.add_run inning: 8 team.score # => {"Astros"=>{1=>0, 2=>0, 3=>2, 4=>0, 5=>1, 6=>0, 7=>0, 8=>1, 9=>0}} team.generate_total # => 4
Real World Usage
This may seem like a simple program to build out. However, to properly implement the program to pass all of the tests you will need to work with nested hashes, maintaining value states for data, configure a reader, and perform calculations on nested hash values. This is one of my favorite coding questions to give devs that I'm interviewing since it reveals their knowledge of hashes and how to work with classes.