Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,878 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!