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 trialMichael Casey
197 Pointsim confused on what I should be doing here and what it would look like if I did this correctly.
why is this not working?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head> Document.write(Mikes website);
<body>Document.write(Body paragraph);
</body>
<script>
Document.write(this is the scipt of mike);
</script>
</html>
3 Answers
Peewee Silva
14,729 PointsMichael,
First, every time you use Javascript in a HTML file you need write your code inside the <script> tags.
Second, you need use quotes on the parameter received by the method, because it's a string, and when we write strings, we use then between quotes, singles or doubles quotes. Example: Document.write("this is the script of mike");
andren
28,558 PointsThere are quite a few reasons:
All JavaScript code must go inside <script> tags, it can not be placed anywhere else in a HTML file.
document
has to be written in lowercase, JavaScript is case-sensitive, so the case matters.Strings, which is what is used to represent arbitrary text, has to be wrapped in quotes. It can't just stand on its own like you have done it in your code.
The challenge asks you to write "Welcome to my site", that's the only message it asks you to write. It is not asking you to describe the structure of the webpage, or anything like that.
If you remove all of the code outside the <script> tag, fix the case of document
, put quotes around your string and actually write the right message like this:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
</body>
<script>
document.write("Welcome to my site"); // document is case sensitive, and text has to be wrapped in quotes
</script>
</html>
Then the code will work.
Michael Casey
197 Pointssuper helpful thank you!
Reuben Varzea
23,182 PointsReuben Varzea
23,182 PointsHi there! Document.write() is going to expect whatever you pass it to be contained inside of quotes (single or double, your preference).
Also, any of your scripting needs to be done either within the <script> tags or inside of javascript file.