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 Write Another Program

Robert Booth
Robert Booth
2,290 Points

How to open an alert dialog box after passing Task 1?

I passed the first task by adding a pair of scripts but everytime I try to add the alert dialog box it no longer passes the first task. What am I doing 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 src="script.js"></script>
</body>
</html>

2 Answers

to open an alert dialog box in the index.html you will need.

<script>
alert("what ever you want to alert");
</script>

if you are in a js file then it would look the same without the <script> tags.

hope this helps

also you need to delete the src="script.js" you do not need this in the <script> tag because you are adding the JavaScript right to the html. you only need src="script.js" if you are adding a different file to the index.html page.

Robert Booth
Robert Booth
2,290 Points

Thanks for your response Eric. However, everytime I add this to the code it brings back an error message saying "It looks like Task 1 isn't passing" or "you didn't call the alert function". Am I supposed to be entering the alert dialog box outside the body?

ok so the first task is asking you to insert a script tag in the between the body tag.

<body> \\ already in the code 
   <script></script> \\ code you need to complete task 1.
</body> \\ again already there

second task is asking for this insde the script tags

<script>alert('Warning');</script>

make sure you use the cap W the tests are case sensitive if it uses a capitalized letter you have to too.

Robert Booth
Robert Booth
2,290 Points

Oh wow thanks a lot Eric! For some reason I thought the two tasks were correlated so I thought the "script.js" tag needed to be included as well in the second task. This is my first time learning a programming language so I am kind of trying to learn the ropes.

no problem. happy coding