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

An Phuc Huynh
seal-mask
.a{fill-rule:evenodd;}techdegree
An Phuc Huynh
Full Stack JavaScript Techdegree Student 7,501 Points

workspace has problem with document.write();

when I used document.write() to launch Workspace; it doesn't display on review but it works when I change to alert().

document.write() works when I used brackets instead of workspace.

3 Answers

Steven Parker
Steven Parker
231,236 Points

The workspace creates a webserver that your browser connects to, so it's your browser that provides the preview. And unlike your editor, browswers don't render the page until the script is completely finished. But "alert" is immediate.

As you progress, you'll soon learn other methods for creating fully interactive scripts in the browser.

use document.write () instead of Document.write();

Steven Parker
Steven Parker
231,236 Points

Isn't that what he said he was using?

Walter Young
PLUS
Walter Young
Courses Plus Student 3,523 Points

I was having a similar problem - I realized document.write doesn't work for me if I try to preview the .js file directly. Instead, I need to preview the index.html file that is linked to the js file. That seemed to fix things for me. I would imagine this has something to do with how browsers handle document.write()?

Steven Parker
Steven Parker
231,236 Points

If you preview the .js file directly, you'd only see the code itself. You need to look at the page to see the results of the code running.