Welcome to the Treehouse Community
Looking to learn something new?
Ruby Loops Confusion
So, I realize that my code is pretty far off, but I'm confused here.
1) I can't seem to add the value of 'number' to the numbers array without erasing the array and setting the value to the '0'.
2) I'm pretty confused about what the question is asking me to do--and I think my code reflects this!
Any help would be greatly appreciated!
numbers =  number = 0 numbers = number loop do number + 1 if numbers > 3 break end end
Tim Knight28,888 Points
I haven't gone through this particular course so I'm not sure what concepts they've taught that led up to this, but I think I can give you enough information to help you solve your issue.
First you're wanting to append the value to the array with each iteration of the loop so instead of
numbers = number on the outside of the loop you'll want to put
numbers << number inside of the loop. The << method is a shorthand way of appending an item to a list in Ruby (shorthand of the push method). Next you want to take the current value of number (which is 0) and add one to it. You would do this with
+= so you're saying "add this value to the current value and make the variable equal that". Since it wants you to end the loop at 3 items you'll want to do
>= instead of just
> so it'll end right at 3 instead of just items greater than.
With all of that you should have something that looks like this:
numbers =  number = 0 loop do numbers << number number += 1 break if numbers.size >= 3 end