Daquon Daquon - 3 months ago 7
Ruby Question

Ruby Loop Countdown method not Counting down

I'm trying to define a method that countdowns 10 to 0 and at the end returns HAPPY NEW YEARS! however i don't want i"am doing wrong?

def countdown(number)
while number > 0
puts "#{number} SECONDS(S)!"
number -= 1
end
"HAPPY NEW YEAR!"
end

Answer
def countdown(number)
  while number > 0
    puts "#{number} SECONDS(S)!"
    number -= 1
  end
 puts "HAPPY NEW YEAR!"
end

I added a puts on the last line of your code. You method is counting down to 0 seconds, but the last line only return the string "HAPPY NEW YEAR!", and does not print it to the screen. Or if you need to return the string and print it on the screen, you can do p "HAPPY NEW YEAR!"

Comments