Some "syntax" questions


#1



https://www.codecademy.com/courses/web-beginner-en-JwhI1/2/4?curriculum_id=50a3fad8c7a770b5fd0007a1


The problem I had was that when I "ran" my code (first code) "case 37" had ('img') in single quotation and it would give me an error every time I tried to "ran" it even though the rest is correct. Then i searched the forum of Codecademy and found out that the incorrect part was in "case 37: ('img')" but I had to put the double quotation (second code) so it would be the same as the rest of them. I rewrote the code and it "ran" perfect but when I did a test and put back the single quotation it "ran" again (something that didn't happen before)!
My question is: I have to put the same quotations every where and need to be exactly the same throughout my code (p.g. coding on Notepad++) OR this is just a bug of the exercise?

Thanks in advance!!


````````````````````````````````(1st code incorrect)``````````````````````````````````
$(document).ready(function() {
    $(document).keydown(function(key) {
        switch(parseInt(key.which,10)) {
			// Left arrow key pressed
			case 37:
				$('img').animate({left: "-=10px"}, 'fast');
				break;
			// Up Arrow Pressed
			case 38:
				$("img").animate({top: "-=10px"},"fast");
				break;
			// Right Arrow Pressed
			case 39:
				$("img").animate({left: "+=10px"}, "fast");
				break;
			// Down Arrow Pressed
			case 40:
				$("img").animate({top: "+=10px"}, "fast");
				break;
		}
	});
}); 

```````````````````````````````(2nd code correct)`````````````````````````````
$(document).ready(function() {
    $(document).keydown(function(key) {
        switch(parseInt(key.which,10)) {
			// Left arrow key pressed
			case 37:
				$("img").animate({left: "-=10px"}, 'fast');
				break;
			// Up Arrow Pressed
			case 38:
				$("img").animate({top: "-=10px"},"fast");
				break;
			// Right Arrow Pressed
			case 39:
				$("img").animate({left: "+=10px"}, "fast");
				break;
			// Down Arrow Pressed
			case 40:
				$("img").animate({top: "+=10px"}, "fast");
				break;
		}
	});
});


#2

@michaelangel1234,

It is not exactly a bug....
it is the code-checker
which is checking the cases and expecting a double-quote-" " encapsulation....

You could write the code as you did in your Post
but some people will then come out and ask you to be consistent....

With a google search
== discussions / opinions ==
jQuery double quote vs single quote site:stackoverflow.com
for instance
http://stackoverflow.com/questions/7027986/single-or-double-quotes-in-jquery
http://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript


#3

Oh OK , thanks a lot :grinning:!


#4

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.