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 Basics (Retired) Working With Numbers Doing Math

Preview page is not working for doing math video.

My work looks like this:

var secondsPerMin = 60;
var minsPerHour = 60;
var hoursPerDay = 24;
var daysPerWeek = 7;
var weeksPerYear = 52;
var secondsPerDay = secondsPerMin * minsPerHour * hoursPerDay;
document.write('There are ' + secondsPerDay + ' seconds in a day');
var yearsAlive = 43;
var daysPerYear = 365;
var secondsAlive = secondsPerDay * daysPerYear * yearsAlive;
document.write("I've been alive for more than " + secondsAlive + " seconds!");

I've checked the questions & answers section, mine looks correct, but I would like to see the result. It appears to be a bug in this video section?

Zachary Fine
Zachary Fine
10,110 Points

Why are you using document.write? Im not exactly sure what you are asking but...

Document.write will add the "string" to the page. (and probably eliminate everything else on the page)

If you are doing it in the TeamTreeHouse Console. You can do a console.log("Hello my name is "+ name);

Hi Viki Bigler, just letting you know I've formatted your code into a code block to make it easier to read.

Please refer to the Markdown Cheatsheet (linked below the text boxes used to add your question, comments or answers) on how to format code blocks.

1 Answer

The preview function of Workspaces won't run/execute/display JavaScript code directly, you have to preview a HTML, PHP or similar file and have it call the scripts you want to run.

So, make sure you have an index.html file that references/loads that scripts.js file correctly. Wherever the script tags go in that HTML file is where the document.write will output the result.