- If the dog's age is 1, the script sets the human age to 15.
- If the dog's age is 2, the script sets the human age to 24.
- If the dog's age is greater than 2, the script uses the formula human_age = 24 + (dog_age - 2) * 5 to calculate the dog's age in human years.
Created
May 2, 2026 03:36
-
-
Save brandonhimpfen/7aaa8fb8b7c560a5f4a154a3338c731c to your computer and use it in GitHub Desktop.
Ruby script to convert a dog's age to human years.
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
| dog_age = 6 # replace with the actual age of your dog | |
| human_age = 0 | |
| if dog_age == 1 | |
| human_age = 15 | |
| elsif dog_age == 2 | |
| human_age = 24 | |
| else | |
| human_age = 24 + (dog_age - 2) * 4.5 | |
| end | |
| puts "A #{dog_age}-year-old dog is #{human_age} years old in human years." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment