I am beginning learning how to code and tried to program a calculator through a course in codecademy.
The task:
We need to set up a single .click() listener that when the user clicks a #numbers a (Use .not() to exclude the #clear and #clearall buttons), will take the .text() of the button, append that to number, set the .text() of totaldiv to number, and finally call testNumLength, passing in number as the parameter.
The interfase alsways saying that my .click() isn’t correctly defined and I don’t know how to fix my Code.
You can see my full code for html, jQuery, and javascript here https://jsfiddle.net/6rvsbLcd/2/
var number = "";
var newnumber = "";
var operator = "";
var totaldiv = $("#total");
totaldiv.text("0");
$("#numbers a").not("#clear,#clearall").click(function(){
$("#numbers").html("number"); {
$("#totaldiv").text("number");
}
});
});
i don’t even know where to start, there are several flaws within your code.
i am unsure why you use curly brackets, {}, within this lines, they are not needed.
from the instructions:
Takes the .html() of the number button and appends that to number
to retrieve a value with .html(), it shouldn’t have any arguments, why do you give it an argument of "number"?
We only want to retrieve the value of the element clicked, for which we can use $(this) to select the element, so to get the html value of the current element you get $(this).html()
the retrieved value should then be appended to number variable, this code is currently completely missing
from the instructions:
Sets the .text() of totaldiv to number
both totaldiv and number are variables, but looking at your code: