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

In task 1, I inserted to correct code. In task 2, I inserted the correct code (as the alert pops up) but it fails me???

Task 2 says that task 1 is no longer valid. When I try to correct the file in task 1 to match task 2 file, it fails me as well. I'm not understanding what it's asking of me.

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

</body>
</html>
Steven Parker
Steven Parker
216,045 Points

The code shown here is the initial code of the challenge — it doesn't look like you've started yet.

Please show the code that you submit when you experience the issue.

7 Answers

Steven Parker
Steven Parker
216,045 Points

Until you post your code for analysis, here's a hint to start with .. a number of questions about this challenge have been asked by folks who are adding more than the instructions actually ask for. So be careful of that.

Steven Parker
Steven Parker
216,045 Points

Now that I see the code, I can explain what happened.

The challenge asks for one set of script tags, and then to put some code between them. But I see you had two sets of script tags. And the first set ("<script src="shout.js"></script>") reference an external script file named "shout.js" that is not part of this challenge.

And the second set have the alert function in them, but it prints "I DID IT". The instructions asked for it to print "Warning!".

And to show your code on separate lines (and without other unintended alterations), use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

Brandon Benefield
Brandon Benefield
7,739 Points

Always read your instructions very carefully.

1) Add opening and closing script tags inside the body of the page.

So we add the open and closing script tags to suggest the use of JavaScript

2) Inside the script tags, write a function that will open an alert dialog with the message 'Warning!'

Now we need to write a function that will call the alert() method then we call that function

SPOILER ALERT

SPOILER ALERT

SPOILER ALERT

<script>
  function alertFunc() {
    alert('Warning!');
  }
  alertFunc();

// or just simply

alert('Warning!');
</script>
Steven Parker
Steven Parker
216,045 Points

:warning: That's also a case of writing more than the instructions actually ask for; but in this particular instance, you managed to pass anyway.

:point_right: I strongly recommend (to Anik and other students) to ignore this spoiler.

Brandon Benefield
Brandon Benefield
7,739 Points

I added in just using the alert method Steven Parker

Steven Parker
Steven Parker
216,045 Points

Presenting two different solutions might be confusing, particularly since the first one deviates from the instructions. I'm not a fan of spoilers in general, I think most folks learn much more effectively by solving it themselves with a bit of help.

I'm two days old on this thing. So sorry. I will try to figure that out. Thanks for your reply!

Steven Parker
Steven Parker
216,045 Points

I'll be happy to help, just show the code that you're submitting when you get the error.

And when posting code to the forum, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

So I don't know how but I had passed the previous task. Now onto another challenge task and the same thing happens but I didn't really learn from the first. Task 1 was answered correctly. I move on to task 2. It asked that inside the shout.js I create an alert between the body.

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

The pop up alert comes on but the response is "Oops! It looks like Task 1 is no longer passing."

I go back to task 1 but the answer is the same. I pass and return to Task 2 to find myself in the same circle.

Hopefully that clarifies my question of how do I get out of this circle.

To be clear, the above code was on different line items. Not in one live as displayed. I'm not sure why it's showing that way.

I guess never mind. I took the test and it now has passed me. I promise I kept answering the same and was careful with spaces, caps, etc. Hopefully I'll find clarity.

I'm having the same problem and I've been working on it for two days and getting frustrated. I'm not sure where I'm going wrong. I've looked back at all the examples and they all match. I can get the first task done but can't figure out the second.

<body> <script src ="alerts.js"></script> <script> alert("Warning!")></script>

what am i doing wrong?

Brandon Benefield
Brandon Benefield
7,739 Points

@jami Remove your first <script src> tags and only leave the the one with your alert method.

The way you have it setup at the moment, you're calling two different scripts and that's most likely why you're not passing.

I"m still having trouble and i took your advice brandon but it still says something is wrong. it own't let me call the function <script src =alert ("Warning!")></script>

Steven Parker
Steven Parker
216,045 Points

You won't use the "src" attribute here, that's just for loading in scripts from external files.

Your code should go between the starting and ending "script" tags. You had that part right back on Oct 20 but then an extra set of tags was causing a problem.