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 Using the Console

problem

what did I do wrong

index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script>
 <script>'Begin Program'</script>
document.write("Welcome to JavaScript Basics");

</script>
</body>
</html>

3 Answers

Your document.write() statement is outside of your <script> tags.

Also you forgot your console.log() statement for "Begin Program".

Your code should look something like this...

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

  console.log("Begin Program");
  document.write("Welcome to JavaScript Basics");

</script>
</body>
</html>
Bob Sutherton
Bob Sutherton
20,160 Points

Daniel Holmes, as shown above, you do not want to have the extra set of script tags. You should only wrap your JavaScript code in one set of script tags. Those tags let the browser know that it is dealing with some code, in this case JavaScript.

In JavaScript there are no markup tags or headings like in HTML. Instead, comments are used to demarcate different places in the code so that it is easier for you or another programmer to follow what is going on.

Console.log() is used to log messages is to your browser's console, which can be accessed with ctrl+shift+j on a windows computer like I use. On a mac, I think it is cmd+option+j or something like that.

So one of the things console.log() allows you to do is to check whether you have arrived at a certain point in your script.

Daniel Holmes I see your having trouble with your element tags. I would advise you before you go further learning JavaScript that you have a solid foundation of element tags. lets quickly break down this process:

just like in HTML tags, the script tag works the same way. When writing JavaScript inline and or linking to an JS file, all JS needs to be Inside the tags, just like HTML. see below:

<div>
<P>Hello World!</p>
</div>
<script>
alert("Hello World!");
</script>

this is the structure for elements. I hope this helps. If you have any questions please feel free to ask us.