Last active
August 29, 2015 14:13
-
-
Save huezoaa/2a3ac9126feeaff33894 to your computer and use it in GitHub Desktop.
Happy New Year Countdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Homework assignment. Ruby Methods 2. | |
# Question #1 | |
def countdown(n=10) | |
(0..n).each { |count| | |
p (n-count) != 0 ? "#{n-count}" : "Happy New Year!" | |
# Because .each returns an array that can't be indexed, | |
# p will print each element as it gets created | |
# by the loop. But "print" waits unitl the array is complete to spit it out! | |
sleep 1 | |
} | |
# puts "Happy New Year!" | |
end | |
(1995..2005).each { countdown() } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment