Hello everyone, I am building my calculator and I have run into a small syntax error that is breaking everything. I have used codepen’s “analyse js” feature and it just tells me I have a "undefined ) "
My project https://codepen.io/Dylanbozarth/pen/vYYKVNX
Here is my code
Thank you in advance for your help.
$(document).ready(function() {
//store input from user
var inputs=[""];
//string to store current input
var totalString;
// validtion array without dot
var operators1 = ["add", "subtract", "divide", "multiply"];
// with the dot
var operators2=["."];
var nums = [0,1,3,4,5,6,7,8,9];
// includes checks a value to see if it's true
function getValue(input){
if(operators2.includes(inputs[inputs.length-1]===true && input==="decimal")){
console.log("too many 'decimals'");
}
else if(inputs.length===1 && operators1.includes(input)===false){
inputs.push(input);
}
else if(operators1.includes(inputs[inputs.length-1])===false){
inputs.push(input);
}
else if(nums.includes(Number(input))){
inputs.push(input);
}
}
function update(){
totalString = inputs.join("");
$("#display").html(totalString);
}
function getTotal(){
totalString = inputs.join("");
$("#display").html(eval(totalString));
}
//eval = evaluate
$("a").on("click", function(){
if(this.id==="clear"){
inputs=[""];
update();
}
else if(this.id==="equals"){
getTotal();
}
else{
if(inputs[inputs.length-1].indexOf("add","subtract","multiply","divide","decimal")===-1){
getValue(this.id);
}
else{
getValue(this.id);
}
}
});
//using this.id will select what was clicked by id
});