Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Numbers Working with Numbers Create a Program with Math

Wrote the same code as shown in video still not working?

const secsPerMin = 60; const minPerHour = 40; const hourPerDay = 24; const dayPerWeek = 7; const weeksPerYear = 52;

const secsPerDay = secsPerMin * minPerHour * hourPerDay; document.write('There are ${secsPerDay} seconds in a day');

Wrote above code and answer I got in display was.

There are ${secsPerDay} seconds in a day

are you using backticks in you document.write function call?

4 Answers

From what you have posted, it looks like you are using single quotes in you document.write function. You need to use backticks for template literals in JavaScript. Replace the single quotes with backticks. It's the key right above the tab key. You also have minPerHour = 40; So the answer won't be correct. Hope this helps.

Salim Nasir
Salim Nasir
1,966 Points

The variable you want to display needs the backticks to be able to display the code properly.

${} is whats needed to be able to fully use template literals backtick feature. make sure to properly place the backticks.

The error is: document.write('There are ${secsPerDay} seconds in a day'); Should use backtick like: document.write(There are ${secsPerDay} seconds in a day);

Because the single quotation will make everything in that single quotation become string, but if you use the backtick ( ), you can bring the value of secsPerDay and put in the string.

Gennadii Chamorsov
Gennadii Chamorsov
9,207 Points

I suppose you wanted to display the result of ${secsPerDay} on your page as html paragraph or heading.

  1. Make sure you linked your JavaScript file to your html with the <script> tags, inside <body> element of your page;
  2. Make sure you used " ` " instead of " ' " for template literal after document.write ;
  3. Make sure to use desired html tags before There are ${secsPerDay} seconds in a day .

Here is the working example:

const secsPerMin = 60; 
const minPerHour = 40; 
const hourPerDay = 24; 
const dayPerWeek = 7; 
const weeksPerYear = 52;

const secsPerDay = secsPerMin * minPerHour * hourPerDay; 

document.write(`<h1>There are ${secsPerDay} seconds in a day.</h1>`);