I am trying to build a calculator using JavaScript without eval. I'm trying to concatenate a variable to store the numbers. Is this the correct way of doing so? Also, when ever I add to the variable it is preceded with undefined.
var calculator = {
run: function(clicked){
num1: "";
num2: "";
numCheck: false;
switch(clicked){
case "1":
document.getElementById("dis").innerHTML += clicked;
if(this.numCheck===false){
if(this.num1==="undefined"){
this.num1 = " ";
this.num1 = this.num1+"1";
}else{
this.num1 = this.num1+"1";
}
}else{
calculator.run.num2 += "1";
};
Am I doing this correctly?