-
Notifications
You must be signed in to change notification settings - Fork 1
/
cal.js
154 lines (148 loc) · 4.24 KB
/
cal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var number1 ="0";
var number2 ;
var operation ="" ;
var afterOper = false;
var count = false;
var width;
const tags = [
document.getElementById("plus").addEventListener("click",()=>add()),
document.getElementById("seven").addEventListener("click",()=>concat(7)),
document.getElementById("four").addEventListener("click",()=>concat(4)),
document.getElementById("one").addEventListener("click",()=>concat(1)),
document.getElementById("zero").addEventListener("click",()=>concat(0)),
document.getElementById("minus").addEventListener("click",()=>sub()),
document.getElementById("eight").addEventListener("click",()=>concat(8)),
document.getElementById("five").addEventListener("click",()=>concat(5)),
document.getElementById("two").addEventListener("click",()=>concat(2)),
document.getElementById("float").addEventListener("click",()=>{if(!count){concat(".");count = true;}}),
document.getElementById("mul").addEventListener("click",()=>mul()),
document.getElementById("nine").addEventListener("click",()=>concat(9)),
document.getElementById("six").addEventListener("click",()=>concat(6)),
document.getElementById("three").addEventListener("click",()=>concat(3)),
document.getElementById("reset").addEventListener("click",()=>clear()),
document.getElementById("div").addEventListener("click",()=>div()),
document.getElementById("equal").addEventListener("click",()=>equal()),
// window.addEventListener("resize",func)
]
function concat(value){
document.get
if(afterOper){
if(value=="."){
number1+=value.toString();
}
else{
number1="";
number1+=value.toString();
}
afterOper = false;
count = false;
}
else {
if(number1=="0"){
if(value=="."){
number1+=value.toString();
}
else{
number1="";
number1+=value.toString();
}
}
else{
number1+=value.toString();
}
}
console.log(number1,number1.length);
changeFontSize();
document.getElementById("display").innerText= number1;
}
function defaults(){
console.log("operator");
}
function clear(){
number1="0";
number2="0";
changeFontSize();
document.getElementById("display").innerText= number1;
operation="";
afterOper = true;
count = false;
}
function add(){
if(!afterOper)
{
auto();
afterOper = true;
number2 = number1;
number1="0";
operation = "add";
}
}
function sub(){
if(!afterOper){
auto();
afterOper = true;
number2 = number1;
number1="0";
operation = "sub";
}
}
function mul(){
if(!afterOper){
auto();
afterOper = true;
number2 = number1;
number1="0";
operation = "mul";
}
}
function div(){
if(!afterOper){
auto();
afterOper = true;
number2 = number1;
number1="0";
operation = "div";
}
}
function equal(){
if(!afterOper){
switch(operation){
case "add":
number1 = (Number(number1) +Number(number2)).toString();
break;
case "sub":
number1 = number2-number1;
break;
case "mul":
number1 = number1*number2;
break;
case "div":
number1 = number2/number1;
break;
default:
console.log("no operations pending");
}
operation = "";
changeFontSize();
document.getElementById("display").innerText= number1;
number2="0";
count = true;
}
}
function auto(){
if(operation!="")
equal();
}
function func(){
width = document.querySelector("#b").clientWidth;
document.getElementById("firstdiv").style.marginLeft = `${(width-300)/2}px`;
document.getElementById("secdiv").style.marginLeft = `${(width-300)/2}px`;
console.log(width);
}
function changeFontSize(){
if((296/number1.length)<25)
document.getElementById("display").style.fontSize=`${296/number1.length}px`;
else
document.getElementById("display").style.fontSize="25px";
}
//window.onload = func;