I’m currently working on the calculator project, and I am running into a problem getting the decimal to work as intended. The way I have programmed it so far, the user input is not completely accurate, and the calculator doesn’t show the near-correct, approximate value until I click the equals button. How can I get the decimal button to work correctly immediately?

The way the JS is currently set up, I have a decimal function that is triggered when the user clicks on the decimal button. Originally, nothing would happen when it was pressed, so I added some code inside my equals button function to treat the decimal as an operator. The problem I am currently running into is that I can’t seem to get the right output during the calculation involving a decimal, nor can I get the exact value after. What should I do here?

Here is the Javascript needed (I think) that matters for this problem:

$("#decimal").click(function(){

var numOfDecs = 0;

for (i=0;i<number.length;i++){

if (number[i] === “.”){

numOfDecs+= 1;

}

}

if (numOfDecs > 0) {

number = number;

number = round(number,9);

totaldiv.text(number);

} else {

operator = “.”;

// number += “.”;

number += (newnumber/10);

//number = round(number,9);

number.toFixed(2);

$("#equals").click();

//totaldiv.text(“0”);

totaldiv.text(number);

}

testNumLength(number);

});

$("#equals").click(function(){

if (operator === “+”){

number = (parseInt(number, 10) + parseInt(newnumber,10)).toString(10);

} else if (operator === “-”){

number = (parseInt(newnumber, 10) - parseInt(number,10)).toString(10);

} else if (operator === “÷”){

number = (parseInt(newnumber, 10) / parseInt(number,10)).toString(10);

} else if (operator === “×”){

number = (parseInt(newnumber, 10) * parseInt(number,10)).toString(10);

}

else if (operator === “sqrt”) {

number = Math.sqrt(parseFloat(number,10)).toFixed(2).toString(10);

}

else if (operator === “^”) {

number = ((Math.pow(parseFloat(newnumber,10),parseFloat(number,10))).toFixed(2).toString(10));

}

else if (operator === “.”) {

number = parseFloat((number+newnumber)*10).toFixed(2).toString(10);

}

totaldiv.text(number);

testNumLength(number);

number = “”;

newnumber = “”;

});

If this is not enough to see the problem, here is the codepen link:

(Note: I used the code academy calculator tutorial to help get me started for this project, so if all else fails, that is something to compare to what I have now.)

Any specific examples of what to change/improve would be greatly appreciated!

Thanks for the help!