Dog Years - console.log

Hi,
I am having difficulty with step 9 of the Dog Years activity and cannot figure out what is wrong in my code. My console.log statement that displays my name and age in dog years, is logging as ‘My name is ${myName}. I am ${myAge} years old in human years which is ${myAgeInDogYears} years old in dog years.’ with the string interpolation not working. Can anyone figure out why this is happening? My full code is below:

// my age

const myAge = 31;

let earlyYears = 2;

earlyYears *= 10.5;

//Accounts for the first two years

let laterYears = myAge - 2;

//to calculate the number of dog years

laterYears *= 4;

console.log(earlyYears);

console.log(laterYears);

//to calculate my age in dog years

let myAgeInDogYears = earlyYears + laterYears;

console.log(myAgeInDogYears);

//write name in all lower case

let myName = ‘Austin Van Grack’.toLowerCase();

console.log(myName);

console.log(‘My name is ${myName}. I am ${myAge} years old in human years which is ${myAgeInDogYears} years old in dog years.’);

Hi!

Does console.log(myAgeInDogYears); print a valid result? (And all the other variables, independently of the interpolation).

It’s hard to tell from here if there’s a small syntax issue because the code is not formatted, see this post for formatting your code:

1 Like

// my age

const myAge = 12;

let earlyYears = 2;

earlyYears *= 10.5;

//Accounts for the first two years

let laterYears = myAge - 2;

//to calculate the number of dog years

laterYears *= 4;

console.log(earlyYears);

console.log(laterYears);

//to calculate my age in dog years

let myAgeInDogYears = earlyYears + laterYears;

console.log(myAgeInDogYears);

//write name in all lower case

let myName = 'Austin Van Grack'.toLowerCase();

console.log(myName);

console.log('My name is ${myName}. I am ${myAge} years old in human years which is ${myAgeInDogYears} years old in dog years.');

[codebyte]

All of the variables printed valid results independently.

Ok, this clarifies the problem.

Template literals need to be wrapped with the backtick `.

E.g.:

spreadType = "vegemite";
console.log(`Wow, who know ${spreadType} goes so well with bread!`);

Thank you for the clarification!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.