Skip to content

Instantly share code, notes, and snippets.

@RaynZayd
Created October 22, 2020 09:24
Show Gist options
  • Save RaynZayd/8b0d07a232f7cd6e8f43306aa5f42beb to your computer and use it in GitHub Desktop.
Save RaynZayd/8b0d07a232f7cd6e8f43306aa5f42beb to your computer and use it in GitHub Desktop.
Dogs mature at a faster rate than human beings. We often say a dog’s age can be calculated in “dog years” to account for their growth compared to a human of the same age. In some ways we could say, time moves quickly for dogs — 8 years in a human’s life equates to 45 years in a dog’s life. How old would you be if you were a dog? Here’s how you c…
/*Dogs mature at a faster rate than human beings. We often say a dog’s age can be calculated in “dog years” to account for their growth compared to a human of the same age. In some ways we could say, time moves quickly for dogs — 8 years in a human’s life equates to 45 years in a dog’s life. How old would you be if you were a dog?
Here’s how you convert your age from “human years” to “dog years”:
The first two years of a dog’s life count as 10.5 dog years each.
Each year following equates to 4 dog years.
With my knowledge of math operators and variables, I'll use JavaScript to convert my human age into dog years.*/
//My age in human years
var myAge = 22;
//Value will change later in code
let earlyYears = 2;
earlyYears *= 10.5;
//First two years in dog years
let laterYears = myAge - 2;
//Number of dog years
laterYears *= 4;
console.log(earlyYears);
console.log(laterYears);
//My age in dog years
var myAgeInDogYears = earlyYears + laterYears;
//My name all in lower cases
var myName = 'RAYN'.toLowerCase();
console.log(`My name is ${myName}. I am ${myAge} years old in human years which is ${myAgeInDogYears} years old in dog years.`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment