Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

What am I doing wrong ?

In the Ruby challenge " Using a while loop, increment the value of the variable i as long as it remains less than 5"

i = 0 while i < 5 i =+ 1 end

It says "Your code took too long to run" What's wrong with my answer?

Thanks

Brandon McClelland
Brandon McClelland
4,645 Points

You've got =+ instead of +=

Add AND assignment operator, adds right operand to the left operand and assign the result to left operand. c += a is equivalent to c = c + a

Thanks :-)

Michael Hall
Michael Hall
Courses Plus Student 30,909 Points

Bill McKinnon, You added your answer as a comment. It's a little confusing, but if you look a little lower on the page there is a "add an answer" section. You have to add your answer here to get your point

Ahh!! Thank you Michael!

1 Answer

Correct answer:

i = 0

while i < 5
  i += 1
end

You mistyped the += operator. Your code would be more readable and you may pick up on these types of mistakes easier if you format and indent your code as well.

If my answer was useful to you please vote it as best answer :) Thank you!