Jump to content

Problem with CodeCademy code? (JavaScript)

Hi guys!

 

I'm making an interactive website on CodeCademy to kill some time and i noticed something.

In step 7/8 the hint says the code should look like this: 

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

But then i get an error to check my $('.menu').animate() but there is nothing wrong with it. 

 

so i tried to change my code a bit and changed the

$('.menu').animate({left: "-285px"}, 200);

to 

 

  $('.menu').animate(){      left: "-285px"    }, 200);

and CodeCademy says it is good. BUT then i get the error: Uncaught SyntaxError: Unexpected token {

 

 

Sooo is my code wrong or is it an bug in CodeCademy?

[CPU: AMD FX-6100 @3.3GHz ] [MoBo: Asrock 970 Extreme4] [GPU: Gigabyte 770 OC ] [RAM: 8GB] [sSD: 64gb for OS] [PSU: 550Watt Be Quiet!] [HDD: 1TB] [CPU cooler: Be Quiet! Shadow Rock Pro Sr1]  -Did i solve your question/problem? Please click 'Marked Solved'-

Link to comment
https://linustechtips.com/topic/268084-problem-with-codecademy-code-javascript/
Share on other sites

Link to post
Share on other sites

TBH, I almost never use Jquery's animate, CSS just does it better unless you're doing something fiendishly complex BUT, the correct code is

$('.menu').animate({left: "-285px"}, 200);

Soooo, not sure why you're getting an error on that. I guess it may be a bug with their tutorial

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

TBH, I almost never use Jquery's animate, CSS just does it better unless you're doing something fiendishly complex BUT, the correct code is

$('.menu').animate({left: "-285px"}, 200);

Soooo, not sure why you're getting an error on that. I guess it may be a bug with their tutorial

So i had the code corrent on the first try but it is just a bug, alright :) 

And i do to, CSS3 and HTML5 are muuuuch easier to animate with.. 

[CPU: AMD FX-6100 @3.3GHz ] [MoBo: Asrock 970 Extreme4] [GPU: Gigabyte 770 OC ] [RAM: 8GB] [sSD: 64gb for OS] [PSU: 550Watt Be Quiet!] [HDD: 1TB] [CPU cooler: Be Quiet! Shadow Rock Pro Sr1]  -Did i solve your question/problem? Please click 'Marked Solved'-

Link to post
Share on other sites

Hi guys!

 

I'm making an interactive website on CodeCademy to kill some time and i noticed something.

In step 7/8 the hint says the code should look like this: 

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

But then i get an error to check my $('.menu').animate() but there is nothing wrong with it. 

 

so i tried to change my code a bit and changed the

$('.menu').animate({left: "-285px"}, 200);

to 

 

  $('.menu').animate(){      left: "-285px"    }, 200);

and CodeCademy says it is good. BUT then i get the error: Uncaught SyntaxError: Unexpected token {

 

 

Sooo is my code wrong or is it an bug in CodeCademy?

This might be a bug in CodeCademy, because I can see where in the changed code it went wrong. The code between the { } needs to be between the parenthesis of the animate() method, and there is and extra closing bracket, either the one on the first line before the brace, or the last line before the semi colon. I'm assuming you know the issue, but yea, this is possibly something you might want to contact them about

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×