-
-
Save keithtom/5333069 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def leap_year?(year) | |
if year % 4 == 0 | |
puts "I am divisible by 4!" | |
true | |
elsif year % 100 == 0 | |
puts "I am divisible by 100!" | |
false | |
elsif year % 100 == 0 && year % 400 == 0 | |
puts "I am divisible by 100 and 400!" | |
true | |
elsif year % 4 == 0 && year % 100 == 0 && !(year % 400 == 0) | |
puts "I am divisible by 4, 100 but not 400" | |
false | |
else | |
puts "The else condition" | |
false | |
end | |
end | |
# got these values from the spec | |
puts leap_year?(4) | |
puts leap_year?(100) | |
puts leap_year?(400) | |
puts leap_year?(3) | |
puts leap_year?(1988) | |
puts leap_year?(1989) | |
puts leap_year?(1998) | |
puts leap_year?(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment