Null Errors :: 0x10

Back to the wonderful world of "Exactly right except for a single keystroke" we go.

If it was written correctly, this program would output a random number between 5 and 500. But due to a typo, it'll fail to behave as expected.

@score = 0

5.times { @score += rand(1..100) }

p @scores

(1) If the code was run as-is, what will the output be?

# [ANSWER 1] #

 nil

(2) If the same typo was present but the score was stored in a local variable instead of an instance variable, would you get the same result, or would the program behavior change?

# [ANSWER 2] #

The program would crash (raising a NameError) with the message:
"undefined local variable or method 'scores' for main"

 ...

 It's worth noting that local variable definitions and method
 calls can be indistinguishable from one another in Ruby when
 neither have been defined, so that's why both are mentioned
 in the same error message.

 See [0xFF01] for more details on that topic.
 (Linked in the footnotes)

The field notes for this exercise are not included in the free sample, but will be provided in the paid version of this guidebook.

You can preorder now to be among the first to gain access when it is released.