Justin Sze Wei Teo9,418 Points
Question on "break loop at 3 items in array" Challenge
Why is it that when I use numbers.length = 3, as opposed to numbers.length >=3 in the if statement, it doesn't work?
Shouldn't it also work as well, since the moment the no. of array items hits the equivalent of 3, it will break the loop?
That is, why doesn't the following work?
numbers =  number = 0 loop do numbers.push(number) number + 1 if numbers.length = 3 break end end
You're using a single equal sign there so it's trying to do an assignment rather than an equality comparison.
Also, you're not changing the value of
number. You're adding 1 to it but you're not assigning that back to
You can do
number = number + 1 # or number += 1
Either of those will add 1 to the current value of
number and store the result back into
Your existing code is continually pushing 0 onto the array which I don't think should be passing.