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

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

Can someone help me with this challenge?

https://www.codecademy.com/courses/ruby-beginner-en-XYcN1/2/2?curriculum_id=5059f8619189a5000201fbcb

Thats the challenge im having reall trouble grasping what the next! method accomplishes here. also i suck at modulo so can you help me with this problem this is what i ended up doing.

i = 20 loop do i -= 1 next if i % 1==0 print "#{i}" break if i <= 0 end

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Here was my solution to your challenge:

i = 20
until i == 0 do
  i -= 1
  next if i % 2 != 0
    print "#{i}"
end

As a note, the next is to tell it hey... if i modulus 2 is not equal to 0 (ie the number is odd) skip over this print statement and continue with the loop. Hope that makes sense!