-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
139 lines (137 loc) · 3.08 KB
/
main.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
function one() {
var x = document.getElementById('input').value;
if (x == 0) {
document.getElementById('input').value = 1;
}
else {
document.getElementById('input').value += 1;
}
}
function two() {
var x = document.getElementById('input').value;
if (x == 0) {
document.getElementById('input').value = 2;
}
else {
document.getElementById('input').value += 2;
}
}
function three() {
var x = document.getElementById('input').value;
if (x == 0) {
document.getElementById('input').value = 3;
}
else {
document.getElementById('input').value += 3;
}
}
function four() {
var x = document.getElementById('input').value;
if (x == 0) {
document.getElementById('input').value = 4;
}
else {
document.getElementById('input').value += 4;
}
}
function five() {
var x = document.getElementById('input').value;
if (x == 0) {
document.getElementById('input').value = 5;
}
else {
document.getElementById('input').value += 5;
}
}
function six() {
var x = document.getElementById('input').value;
if (x == 0) {
document.getElementById('input').value = 6;
}
else {
document.getElementById('input').value += 6;
}
}
function seven() {
var x = document.getElementById('input').value;
if (x == 0) {
document.getElementById('input').value = 7;
}
else {
document.getElementById('input').value += 7;
}
}
function eight() {
var x = document.getElementById('input').value;
if (x == 0) {
document.getElementById('input').value = 8;
}
else {
document.getElementById('input').value += 8;
}
}
function nine() {
var x = document.getElementById('input').value;
if (x == 0) {
document.getElementById('input').value = 9;
}
else {
document.getElementById('input').value += 9;
}
}
function zero() {
var x = document.getElementById('input').value;
if (x == 0 ) {
document.getElementById('input').value = 0;
}
else {
document.getElementById('input').value += 0;
}
}
function decimal() {
document.getElementById('input').value += '.';
}
function remove() {
document.getElementById('input').value = '';
}
function equal() {
var getInput = document.getElementById('input').value;
var solver = eval(getInput);
document.getElementById('input').value = solver;
}
function plus() {
var x = document.getElementById('input').value;
if (x == 0) {
alert('Invalid input. Please enter a number first');
}
else {
document.getElementById('input').value += '+';
}
}
function minus() {
var x = document.getElementById('input').value;
if (x == 0) {
alert('Invalid input. Please enter a number first');
}
else {
document.getElementById('input').value += '-';
}
}
function multiply() {
var x = document.getElementById('input').value;
if (x == 0) {
alert('Invalid input. Please enter a number first');
}
else {
document.getElementById('input').value += '*';
}
}
function divide() {
var x = document.getElementById('input').value;
if (x == 0) {
alert('Invalid input. Please enter a number first');
}
else {
document.getElementById('input').value += '/';
}
}