let oneTwo=False, operandOne=0, operandTwo=0,oper; let text1=document.querySelector("#text1"); let b0=document.querySelector("#b0"); let b1=document.querySelector("#b1"); let b2=document.querySelector("#b2"); let b3=document.querySelector("#b3"); let bToch=document.querySelector("#bToch"); let bPlu=document.querySelector("#bPlu"); b0.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=0; } else{ operandOne+='0'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=0; operandTwo+=''; } else{ operandTwo+='0'; } text1.value=operandTwo; } } b1.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=1; operandOne+=''; } else{ operandOne+='1'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=1; operandTwo+=''; } else{ operandTwo+='1'; } text1.value=operandTwo; } } b2.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=2; operandOne+=''; } else{ operandOne+='2'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=2; operandTwo+=''; } else{ operandTwo+='2'; } text1.value=operandTwo; } } b3.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=3; operandOne+=''; } else{ operandOne+='3'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=3; operandTwo+=''; } else{ operandTwo+='3'; } text1.value=operandTwo; } } b4.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=4; operandOne+=''; } else{ operandOne+='4'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=4; operandTwo+=''; } else{ operandTwo+='4'; } text1.value=operandTwo; } } b5.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=5; operandOne+=''; } else{ operandOne+='5'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=5; operandTwo+=''; } else{ operandTwo+='5'; } text1.value=operandTwo; } } b6.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=6; operandOne+=''; } else{ operandOne+='6'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=6; operandTwo+=''; } else{ operandTwo+='6'; } text1.value=operandTwo; } } b7.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=7; operandOne+=''; } else{ operandOne+='7'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=7; operandTwo+=''; } else{ operandTwo+='7'; } text1.value=operandTwo; } } b8.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=8; operandOne+=''; } else{ operandOne+='8'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=8; operandTwo+=''; } else{ operandTwo+='8'; } text1.value=operandTwo; } } b9.onclick=function(){ if(oneTwo==False){ if(operandOne==0){ operandOne+=9; operandOne+=''; } else{ operandOne+='9'; } text1.value=operandOne; } else if(oneTwo==True){ if(operandTwo==0){ operandTwo+=9; operandTwo+=''; } else{ operandTwo+='9'; } text1.value=operandTwo; } } bToch.onclick=function(){ if(oneTwo==False){ operandOne+='.'; text1.value=operandOne; } else if(oneTwo==True){ operandTwo+='.'; text1.value=operandTwo; } } bPlu.onclick=function(){ oneTwo=True; text1.value="+"; oper="plu"; } bMin.onclick=function(){ oneTwo=True text1.value="-"; oper="min"; } bPro.onclick=function(){ oneTwo=True text1.value="*"; oper="pro"; } bCha.onclick=function(){ oneTwo=True text1.value="/"; oper="cha"; } bRes.onclick=function(){ switch(oper){ case "plu": res=+operandOne+ +operandTwo; break; case "min": res=+operandOne- +operandTwo; break; case "pro": res=+operandOne* +operandTwo; break; case "cha": if(operandTwo!=0){ res=+operandOne/ +operandTwo; } else{res="Error" } break; } text1.value=res; operandOne=res; operandTwo=0; }

Теги других блогов: веб-разработка JavaScript калькулятор