Why we need to declare always a new variable?


#1

Why the excercise does not accept the previously declared variable for project-buttons? The one you have used to present the OnClick listener. Like this:

var $projButtons = $(".projects-button").on("click", function() {

var $projs = $(".projects").toggle();
$projButtons.toggleClass("active");

You can use it to toggle the class and it will work perfect. However this will not be accepted, you need to declare a new variable in order to get a green and continue. Like this:

var $projButtons = $(".projects-button").on("click", function() {

var $projs = $(".projects").toggle();
var $projButs = $(".projects-button").toggleClass("active");

#2

==Q1== The code presented is not complete, with a missing } and )
==Q2== could you provide a link to the lesson....??


#3

Yes, it is only a incomplete code fragment, I know. But, the idea is on the third line. First example is working fine, but not accepted by the test checker. You have to code it like in the second example to be able to continue. Why?


#4

And the link i asked for ...??!


#5

https://www.codecademy.com/courses/learn-javascript/lessons/javascript-dom/exercises/javascript-with-html-css?action=lesson_resume


#6

This topic was automatically closed after 7 days. New replies are no longer allowed.