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 trialIsmael Ramirez
3,627 Pointshello I am trying to put this javascript code var x = 100; var a = 30; document.write(x - a); into brackets
its telling me ERROR 'document' is not defined. [no-undef] here's the html code
<!doctype HTML>
<html>
<head>
<script src="pelu.js"></script>
<title>Peluche's website</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div>
<h1>PELUCHE</h1>
<ul>
<li><a href="index.html" target="-blank">HOME</a></li>
<li>VIDEOS</li>
<li>PICTURES</li>
<li><a href="contact.html" target="-blank">CONTACT</a></li>
</ul>
</div>
<p><a href="#things">Go to things I like and hate</a></p>
<p><a href="#foods">Go to my favorite food</a></p>
<p><a href="#quotes">Go to quotes</a></p>
<figure>
<img src="images/IMG_20160917_103329.jpg" alt="peluche" width="250px" class="perro-bebe" title="peluche-miados">
<figcaption>Peluche Miados</figcaption>
</figure>
<h1>Peluche's Official Page </h1>
<p>
Hello my name is <em>Peluche</em> and I'm a <a href="https://en.wikipedia.org/wiki/Poodle" target="-blank">poodle</a> and I live in Glendale AZ. My zodiac sign is ♎. I was born over a thousand years ago.<br> When my alien species sent me in an egg form to a volano. Where I hatch. They sent me to earth to exterminate all humans.<br> However I soon found out humans aren't so bad.
<q>Don't take it too seriously</q>
</p>
<section id="things">
<h2>Things I hate the most.</h2>
<ul>
<li>Cats</li>
<li>Cars</li>
<li>Random People</li>
<li>sjw's</li>
</ul>
<h2>Things I like the most</h2>
<ul>
<li>Steaks</li>
<li>Sleeping</li>
<li>Chasing Cats</li>
<li>Barking at strangers</li>
</ul>
</section>
<section id="foods">
<figure>
<h2>My Favorite food</h2>
<img src="cevi.jpeg" alt="ceviche" width="200px" class="ceviche">
<figcaption>ceviche de camaron</figcaption>
</figure>
</section>
<hr>
<section id="quotes">
<h2>Famous Poodle Quotes</h2>
<h3>Famous poodle quote #1</h3>
<q>They're not poodles, they're art. <cite><a href="https://www.brainyquote.com/quotes/rachael_leigh_129337?src=t_poodle">Rachael Leigh</a></cite></q>
<h3>Famous poodle quote #2</h3>
<q>
I wonder if other dogs think poodles are members of a weird religious cult.
<cite><a href="https://www.brainyquote.com/quotes/rita_rudner_104845?src=t_poodle">Rita Rudner</a></cite>
</q>
<h3>Famous poodle quote #3</h3>
<blockquote>I wrote a techno song about the four things I love in Germany to make myself happy, which are my grandfather, my two poodle pets, bread, and a strange but delicious Turkish dish called Doener Kebab.
<cite><a href="https://www.brainyquote.com/quotes/flula_borg_707584?src=t_poodle">Flula Borg
</a></cite>
</blockquote>
</section>
<footer>
<p>Leave me a message at <a href="mailto:www.lecheenpolvo15@gmail.com?subject=hola%20mortales!">lecheenpolvo15@gmail.com</a> for more info</p>
<p><small>©2017 Peluche's Website</small></p>
</footer>
</body>
</html>
1 Answer
Steven Parker
231,271 PointsAdomas has the right idea. Scripts that reference anything in the document should either be contained in an event handler for the DOMContentLoaded event, or they should be included as the vary last item of the <body>
section.
You did not show the script itself, but based on the error, I assume the event handler technique is not used in it.
Adomas Domeika
6,151 PointsAdomas Domeika
6,151 PointsI believe the problem is that you are importing the script in the head, because the head does not have a document, that’s why you are having an error. Try putting it in the body. (<script src=“pelu.js”></script>)