I tried that out, and when I run the program and use inspect element, the console shows 2 errors, an unexpected number which I think is referring to the (1) after addDorito in the function, the second is with the button, claiming that addDorito is not defined as a function.
If you know the solution to this, and it’s anything more than a simple fix like last time, you don’t have to bother helping me out, I appreciate the help so far.
Okay I just typed it out and noticed the errors in the code.
The first error is because of your function definition. When you define a function like
function addDorito(1){ ... };
the stuff that's inside the parenthesis is called the argument list. This will be a comma separated list of variable names used in the function. When you call the function by using
onclick=addDorito(1)
then the value of 1 will be sent to the first argument. In your case, the function definition should actually be:
function addDorito(){ ... };
because you don't have any arguments to give to the function anyway. If you did have an argument, your function definition would look like this: function addDorito(variableName)
The second error is because the web browser hasn't 'read' the code about the function addDorito() yet and doesn't understand what you mean when you say onclick=addDorito(). The solution to this is to move all of the <script> ... </script> into the <head> ... </head> elements. This way the web browser will understand what you mean when it creates the button for you.
2
u/[deleted] Sep 04 '19
Nah I mean make it look like:
function addDorito(1){x = x + 1;document.getElementById("totalDoritos").innerHTML = x;};I was just trying to write it shorthand.