Unit 1, Lesson 5: Menu won't appear, whatever I do!


#1

Hey guys!

I'm a pretty new Codecademy user (and really enjoy it :slightly_smiling: ).

My Problem:
I'm currently doing the 5th lesson of the 1st unit on how to make an interactive website. I tried to make the menu appear for about 1 and half an hour. First I did it on my own, then I tried to get help by the "Get a hint" feature. But: Even when I copy + paste the code from the hint, I still get the error "Oops, try again. It looks like the '.menu' didn't animate into the screen. Check your $('.menu').animate() function."

My code
I didnt change anything in the CSS or HTML, so here's my JS code:

var main = function() {
  $('.icon-menu').click(function() {
    $('.menu').animate({
      left: '0px'
    }, 200);

    $('body').animate({
      left: '285px'
    }, 200);
  });
};`

And also if I click on the Menu in the preview, it doesn't show up anything...

Thank you all for your help!

Skyflyer :smiley:


#2

@skyflyer2002,
With the code presented in your Post
you assign a so-called anonymous function to the variable main.

As the Browser loads the HTML-Document
the =main= function is distributed in memory but NOT executed.....

You could use jQuery's ready() facility

$(document).ready( main );

which will execute the =main= function as soon as the jQuery-ready-flag has been set.....

google search
== the Book ==
jquery [your question] site:developer.mozilla.org
CSS [your question] site:developer.mozilla.org
javascript [your question] site:developer.mozilla.org
[your question] site:jquery.com
[your question] site:getbootstrap.com

== discussions / opinions ==
jquery [your question] site:stackoverflow.com
CSS [your question] site:stackoverflow.com
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
[your question] site:crockford.com
- - http://javascript.crockford.com/code.html
- - http://javascript.crockford.com/survey.html

http://stackoverflow.com/questions/1795438/load-and-execution-sequence-of-a-web-page
http://www.w3schools.com/jquery/trysel.asp


#3

Thank you very much sir!!! Very happy at the moment... Thanks ;D