-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
158 lines (149 loc) · 4.99 KB
/
index.html
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
154
155
156
157
158
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CALCpro</title>
<link rel="stylesheet" href="styles.css"/>
<script src="/myscripts.js"></script>
</head>
<body>
<div class="container">
<header>
<div class="title">CALCpro</div>
<div class="timestamp">
<span class="hrsmins"></span>
<span class="secs"></span>
</div>
</header>
<div class="answers">0<span id="current_operator"></span></div>
<div class="inputs">_</div>
<div class="keyboard">
<div class="btns" id="btn-plus"> + </div>
<div class="btns" id="btn-minus"> -</div>
<div class="btns" id="btn-times"> * </div>
<div class="btns" id="btn-divide"> / </div>
<div class="btns" id="btn-1"> 1 </div>
<div class="btns" id="btn-2"> 2 </div>
<div class="btns" id="btn-3"> 3 </div>
<div class="btns" id="btn-eqls"> = </div>
<div class="btns" id="btn-4"> 4 </div>
<div class="btns" id="btn-5"> 5 </div>
<div class="btns" id="btn-6"> 6 </div>
<div class="btns" id="btn-7"> 7 </div>
<div class="btns" id="btn-8"> 8 </div>
<div class="btns" id="btn-9"> 9 </div>
<div class="btns" id="btn-0"> 0 </div>
<div class="btns" id="btn-clr"> CLR </div>
<div class="btns" id="btn-del"> DEL </div>
</div>
</div>
</body>
<script>
// time setter
localStorage.clear();
function setTime() {
'use strict'
let today = new Date();
let hrs = today.getHours();
let mins = today.getMinutes();
let secs = today.getSeconds();
let hrsmins = make2dgt(hrs) + ':' + make2dgt(mins)
let secstamp = make2dgt(secs);
document.querySelector('.hrsmins').innerHTML = hrsmins;
document.querySelector('.secs').innerHTML = secstamp;
function make2dgt(stdinput) {
if(stdinput < 10) stdinput = '0' + stdinput;
return stdinput;
}
}
setInterval(setTime, 1000);
//bimpimg section
function setBipper() {
'use strict'
let empty = '|';
let dash = '_';
let inputs = document.querySelector('.inputs');
(inputs.innerHTML == '_')? inputs.innerHTML = empty : inputs.innerHTML = dash;
}
const stopBipper = setInterval(setBipper, 1000);
//set for the answer sec
function setAnswBipper() {
'use strict'
let eight = '8';
let zero = '0';
let answers = document.querySelector('.answers');
(answers.innerHTML == "0")? answers.innerHTML = eight : answers.innerHTML = zero;
}
const stopAnswBipper = setInterval(setAnswBipper, 1000);
document.addEventListener('DOMContentLoaded', function(){
let buttons = document.querySelector('.keyboard').children;
Array.from(buttons).forEach(function(btn){
btn.addEventListener('click',function(event){
btn.classList.add("clicked-btn");
setTimeout(() => btn.classList.remove("clicked-btn"),500);
clearInterval(stopBipper);
updatedInputs(event.target.innerHTML);
})
})
});
// common variavle
let numValues = ""; // picks values input
let storeVal = "figureOne"; // pushes first value to localstorage
let operation = []; // holds sign values
function updatedInputs(value) {
let inputs = document.querySelector('.inputs');
if (Number(value) < 10) {
numValues += Number(value);
inputs.innerHTML = numValues;
}
else if (value.trim() === "CLR") {
document.querySelector("#btn-clr").classList.add("clr-clicked");
setTimeout(() => {
document.querySelector("#btn-clr").classList.remove("clr-clicked");
location.reload();
localStorage.clear();
} ,500);
}
else if (value.trim() === "=") {
if(operation[0]) {
setAnswer(numValues,inputs);
} else {
document.querySelector(".answers").innerHTML = numValues;
localStorage.clear();
}
}
else if (value.trim() === "DEL") {
if(numValues.length > 0){
let newVlues = Array.from(numValues);
newVlues.pop(-1);
numValues = newVlues.join("").toString();
document.querySelector(".inputs").innerHTML = numValues;
} else {
document.querySelector(".inputs").innerHTML = "0";
numValues = "";
}
}
else {
operation.push(value.trim());
setAnswer(numValues,inputs);
}
}
function setAnswer(val, inputsSec) {
clearInterval(stopAnswBipper);
let answers = document.querySelector('.answers');
if(localStorage.getItem(storeVal)) {
let answer = eval(`${localStorage.getItem(storeVal)} ${operation[0]} ${val}`);
operation.shift();
localStorage.setItem(storeVal,answer);
answers.innerHTML = answer;
} else {
answers.innerHTML = val;
localStorage.setItem(storeVal,val);
answers.innerHTML = localStorage.getItem(storeVal);
}
numValues = ""
inputsSec.innerHTML = "0";
}
</script>
</html>