Skip to content

Instantly share code, notes, and snippets.

@ethanstenis
Created July 14, 2017 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanstenis/bb8a73e36ae7f63b5cb6e98dc7e66bbc to your computer and use it in GitHub Desktop.
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
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