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) Introducing JavaScript Your First JavaScript Program

Taylor Han
Taylor Han
3,701 Points

Cannot find variable?

Hello, I am in the first stages of the fullstack Javascript course. I am trying to write a sentence into the script, but each time I try to it tells me that it cannot find the variable for "write." I have gone back and rewatched the previous videos but cannot figure out what I am doing wrong.

Thank you

index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>

<body>
</body>

<script>
// script.write();
  script.write("Welcome to my site");

</script>

</html>

Hi Taylor

From what I can see, you are trying to call the .write() method on an object called 'script' which isn't defined and doesn't exist. Try to call the write() method on the global document object. document.write('Welcome to my site');

Let me know if that works!

Antonio De Rose
Antonio De Rose
20,885 Points

lukehegarty give your answer in the answer area, your answer could be the best answer.

2 Answers

Taylor Han
Taylor Han
3,701 Points

Thank you Luke, that worked!

Copying answer into the correct place!

Hi Taylor

From what I can see, you are trying to call the .write() method on an object called 'script' which isn't defined and doesn't exist. Try to call the write() method on the global document object. document.write('Welcome to my site');

Let me know if that works!