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

Including jquery in our project challenge task 2

help here is my code

script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $( "#message" ).hide(); 
  $( "#message" ).click(function() {
 $( "#message" ).show( "slow" );
   });></script>

Help how to fit this is appreciated. link to challenge: http://teamtreehouse.com/library/build-an-interactive-website/introduction-to-jquery/including-jquery-in-our-project

You havent closed your 2nd opening script tag

<script type="text/javascript"

shoud be

<script type="text/javascript">

Hope this helps

8 Answers

Thanks Adam, however I just didnt have the closed tag indented in my question but I fixed that but it still wont work. can you try my code in the challenge? not sure why it still wont work. thanks for your help.

I got it pass by doing the following.

 $(document).ready(function(){
$("#message").hide();
 $("#message").show('slow');
 }); 

Not sure if the document .ready function is required but its force of habit.

Adam Sackfield -

> Not sure if the document .ready function is required but its force of habit.

It's not.

Better to form good habits I would say! Cheers

I would argue, that an exercise should be solved with as little code as possible. Including a line of code you aren't exactly sure how it contributes to the solution, but include it out of habit is symptom of cargo cult programming.

Well not really as I was unsure if the code editor on here needed it. As if it was my project then I would want it wait for the page to load before running any kind of scripts. So as to enhance the site performance during a users visit. Happen I can guide you to research what being pedantic means.

Yes, I. did not have

    (document). ready (function() {

so I'm guessing I need that to select the element in the DOM. Thanks for your help!!!

> so I'm guessing I need that to select the element in the DOM.

Nope.

 $( "#message" ).hide(); 
 $( "#message" ).click(function() {
    $( "#message" ).show( "slow" );
});

In your code you say:

  1. Hide the element
  2. Listen for a a click on the (now hidden) element
  3. When a click is detected, show it slowly.

The obvious question, how does a user click on a hidden element.

.this is my code and its not passing

  $( "#message" ).hide(); 
  $( "#message" ).click(function() {
      $( "#message" ).show( "slow" );
  });

The code challenge has 2 parts, hide the element and then show the element. Your element will never be shown because a user can't click on a hidden element.

Let me know if you still have any questions.

thanks but I'm confused...I thought I was following the steps but I guess I am getting lost. so do i need a command to show it first? at this point its hidden but the user needs to be able to access it?

The directions don't mention anything about "clicking", I think that's the part that's tripping you up. If you cut that part out it should work fine.

Ok I took the click out. It still doesn't work. I've been stuck all afternoon, can someone help with this challenge?

 $("#message").hide(); 
 $("#message") (function() {
 $("#message").show("slow")
 });

I was stuck on this as well. Here is my code. It passed.

<script type="text/javascript"> $("#message").hide(); $("#message").show("slow"); </script>