Hi,
I have declared goStore variable as
let goStore = button1.onclick;
but it is still giving error " You should set the onclick
property of button1
to the variable goStore
."
Hi,
I have declared goStore variable as
let goStore = button1.onclick;
but it is still giving error " You should set the onclick
property of button1
to the variable goStore
."
I have moved your reply to its own topic.
You have two issues.
Issue no.1:
You don’t need to use let
here because goStore
is a reference to a function you will write later in the program.
Issue no.2:
You have this backwards
The way assignment works is whatever is on the right gets assigned to what is on the left
For example
let variableName = "this text is assigned to variableName"
Once you fix those two things then it will pass
Hope that helps
I have also created an issue to update the directions because goStore
should not be referenced as a variable but rather a function.
I think that is leading to some of the confusion here
thanks for the help . Was stuck here racking my brains off
So why is this wrong
button1.onclick = function () {
goStore;
};
Your code is incorrect for the challenge because the lesson wants you to assign the function reference to the button click
Thanks for your reply! I got past the auto grader by using the other code But isen’t the = sign here an assignment ? button1.onclick = function () {
goStore;
};
yes but that isn’t the issue with your code.
In your example you are assigning a function and placing goStore inside of it without calling it. So it wouldn’t fire
You can see the results for yourself by testing it with this code here
button1.onclick = function () {
goStore;
};
function goStore(){
console.log("button 1 was clicked")
}
trying clicking the first button and see that nothing appears in the console
Now call the function, by adding a parenthesis after the function name, and click on the button and see the log statement.
button1.onclick = function () {
goStore();
};
function goStore(){
console.log("button 1 was clicked")
}
Even though that works, you are making it more complicated then necessary.
For button clicks you can assign a function reference to it.
A function reference is value that points to a function without calling it.
When you you click the button, then that function will fire.
For a function reference like the challenge wants you to do, you don’t need to include the parenthesis after the function name.
The function will get called and fire when the button is clicked.
Hope that clears it up
Yes, thanks for that explanation
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.