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 Link to an External Script

Bhavishya Saini
Bhavishya Saini
806 Points

Inside the shout.js file, write the code for an alert dialog with the message 'I DID IT!'

how will i write this code in the shout.js file??

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="shout.js">

    alert("i did it");

  </script>


</body>
</html>
shout.js

9 Answers

To solve this easily for you. When they say "inside the shout.js file", they literally mean the shout.js file next to the index.html file on the tabs at the top. Sat here for almost 15 minutes before realizing it said "FILE"...Coding is fun!

Daniel Vigil
Daniel Vigil
26,473 Points

You are almost there.

The JS code for the alert needs to be in the shout.js file while the <script> tag within the html references the shout.js file.

Reference the previous videos as a refresher.

I think the problem is the interface between Google Chrome and the Treehouse program. Entering identical code (and really, I've checked for typos and other clams) results in numerous responses, including "Well done!" and the instruction to proceed to the next task, after which I get a "Task #1 is no longer running" or an error message, or the instruction to repeat the challenge that I've just completed. Last night I made it a couple of units beyond this code challenge, and the email that I received this morning sent me back to the "shout.js" challenge. It feels like "Groundhog Day!"

Daniel Vigil
Daniel Vigil
26,473 Points

The alert code needs to be within the shout.js code and not in the HTML. You should still keep the script tag in the html which is used for the reference.

Yep, I'm aware that the code as it appears above is incorrect. At this point I don't even remember what I did correctly; I've tried numerous versions. At least one of them worked, after which I was returned to the same challenge when I clicked on the "Keep going" tag, or I was informed that Task 1 had ceased working..

Daniel Vigil
Daniel Vigil
26,473 Points

The code you have provided here. Is this from a prior attempt or is it at task 2? I just want to make sure I am seeing everything at the point you are seeing the error.

Hi, Daniel - Here's the sequence:

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

"Well done! You're doing great!"

<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JavaScript Basics</title> </head> <body> <script src = "shout.js">; </script> <script> alert ("I DID IT!); </script> </body> </html>

"Well done! You're doing great!"

Clicked on “Next task;” sent back to “Inside the shout.js file, write the code for an alert dialog with the message 'I DID IT!'”

Re-entered code, hit “Check work,” got “Oops! It looks like Task 1 is no longer passing.”

 Is this some weird function of the interface between this program and Google Chrome?

 Thanks for your patience and persistence.
Daniel Vigil
Daniel Vigil
26,473 Points

It appears you have too many <script> elements in your code. Your code should look something like this:

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 = "shout.js"> 
</script>  
</body> 
</html>

and your shout.js file should look like this:

alert ("I DID IT!"); 

Thanks, Daniel; I'd tried that. The first time I typed the string:

 <body>
    <script src = "shout.js" alert ("I DID IT!");> </script>

and got the response of:

 "Bummer! You didn't call the `alert()` function inside the `shout.js` file."

I tried it again, and got the hoped-for response of "Well done! You're doing great!" Clicking on "Next task" sent me back to the "I DID IT!" challenge. Submitting the identical string got me a response of "Oops! It looks like Task 1 is no longer passing."

OK. So I went back to Task One and completed that. Repeatedly, and with success. Repeating the "I DID IT!" exercise [<script src = "shout.js" alert ("I DID IT!");> </script>] got me a range of responses from "Bummer! You didn't call the alert() function inside the shout.js file." to "Oops! It looks like Task 1 is no longer passing."

No exit . . .

Daniel Vigil
Daniel Vigil
26,473 Points

For this task it is testing to make sure you have an understanding of using external JavaScript files. Based on the code you have shown a few times you are putting the alert JavaScript code in the index.html which should only have the script tag referencing to the shout.js file. The alert code needs to be in the shout.js file. So your first task is correct because it is asking just for the script tag to be added. When you put in the alert code on the second task you are adding it to the HTML and not the js file. This makes the first task no longer valid since there is code in the script tag.

The video, at 3:33, indicates that the phrase signaled by "alert" should be enclosed in a second set of "<script></script> notations.

Once again, somehow I seem to have gotten the correct solution and the response "Well done! You're doing great!" Once again, when I tried to proceed to the next task, I was directed back to the "I DID IT!" code challenge.