-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.js
88 lines (79 loc) · 2.16 KB
/
logic.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
function evaluate(){
let evaluating = document.getElementById("answer").value;
let equal = eval(evaluating);
document.getElementById("answer").value = equal;
}
var operator1 = null;
var operator2 = null;
var operation = null;
// Clear screen should clear the screen and reset the input field to 0
// TODO: Right now this function just hides the pressed digits. It does not clear the screen
// I want to clear the screen and reset the input values
function clearScreen(){
document.getElementById("answer").value = "0";
operator1 = "";
operator2 = "";
}
// This function displays the value pressed on the page. It only displays 0-9
function display(value){
document.getElementById("answer").value = value;
}
function number(value) {
if (operation === null){
if (operator1 === null){
operator1 = value;
display(operator1);
}
else if (operator1 !== null){
operator1 = operator1.concat(value);
display(operator1);
}
}
else {
if (operator2 !== null){
operator2 = value;
display(operator2);
}
else if (operator2 !== null){
operator2 = operator2.concat(value);
display(operator2);
}
}
}
function decimal() {
document.getElementById("answer").value = value;
}
function add(operator1, operator2) {
//document.getElementById("add").value += operator2
operation == operator1 + operator2;
}
function subtract(operator1, operator2) {
if (operator1 != null && operator1 >= 0){
return operator1 -= operator2
}
else if (operator2 != null && operator2 >= 0){
return operator2 -= operator1
}
}
function multiply(operator1, operator2) {
if (operator1 != null && operator1 >= 0){
return operator1 *= operator2
}
else if (operator2 != null && operator2 >= 0){
return operator2 *= operator1
}
}
function divide(operator1, operator2) {
if (operator1 != null && operator1 >= 0){
return operator1 /= operator2
}
else if (operator2 != null && operator2 >= 0){
return operator2 /= operator1
}
}
function equals() {
if (operation !== null && operator1 !== null && operator2 !== null){
operation = operator1 + operator2
display(operation)
}
}