Created
July 14, 2017 16:03
-
-
Save ethanstenis/bb8a73e36ae7f63b5cb6e98dc7e66bbc to your computer and use it in GitHub Desktop.
This is the solution to the Codewars Kata: How Old Will I be in 2099
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
function calculateAge(birthDate, otherDate) { | |
var age = otherDate - birthDate; | |
if(age === 1) { | |
return 'You are ' + age + ' year old.'; | |
} else if(age > 1) { | |
return 'You are ' + age + ' years old.'; | |
} else if (age < -1) { | |
return 'You will be born in ' + Math.abs(age) + ' years.'; | |
} else if (age === -1) { | |
return 'You will be born in ' + Math.abs(age) + ' year.'; | |
} else { | |
return 'You were born this very year!'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment