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 trialMatthew Fowler
Full Stack JavaScript Techdegree Student 1,672 PointsWrote 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
4 Answers
Tyler Maxwell
Courses Plus Student 42,021 PointsFrom 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
1,966 PointsThe 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.
Hengly AUN
Full Stack JavaScript Techdegree Student 3,225 PointsThe 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
9,207 PointsI suppose you wanted to display the result of ${secsPerDay} on your page as html paragraph or heading.
- Make sure you linked your JavaScript file to your html with the <script> tags, inside <body> element of your page;
- Make sure you used " ` " instead of " ' " for template literal after document.write ;
- 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>`);
Tyler Maxwell
Courses Plus Student 42,021 PointsTyler Maxwell
Courses Plus Student 42,021 Pointsare you using backticks in you document.write function call?