I was working on this lesson with a student today and this bonus section doesn't seem to make a lot of sense to me.
The section explains that you can use the ||= operator to set a value to a variable only if it's value is nil. The issue is that the student is most likely to do something like this:
number_of_turns = gets.to_i
which can never be nil since if you just hit Enter it will result in number_of_turns being set to 0.
Even if the student did something like:
number_of_turns = gets
with the intention of converting it to a integer later it would still not be enough to use the ||= operator since number_of_turns will be set to a empty string when the user hits Enter at the turns prompt.
This PR removes the section completely rather then trying to rewrite it. If we really want to keep it around we could talk about the NaN results and error that is raised when a user hits Enter on the turns prompt and suggestions on how to fix it.
I was working on this lesson with a student today and this bonus section doesn't seem to make a lot of sense to me.
The section explains that you can use the
||=
operator to set a value to a variable only if it's value isnil
. The issue is that the student is most likely to do something like this:which can never be
nil
since if you just hit Enter it will result innumber_of_turns
being set to 0.Even if the student did something like:
with the intention of converting it to a integer later it would still not be enough to use the
||=
operator sincenumber_of_turns
will be set to a empty string when the user hits Enter at the turns prompt.This PR removes the section completely rather then trying to rewrite it. If we really want to keep it around we could talk about the
NaN
results and error that is raised when a user hits Enter on the turns prompt and suggestions on how to fix it.