-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjs.js
142 lines (119 loc) · 3.01 KB
/
js.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
var check = 2;
// var firstNumbers = [0];
// var secondNumbers = [];
//string variable to store the equation
var str = '';
// var opO = '';
// var checker = 'first';
//this variable use jquery to refrance to the display element
var dis = $('#display-opration')
//$('#img').hide()
//use jquery to listen to any click from any button,
//and it add our equation to str;
//and display it on the display element;
$('.btns').on('click', function(event){
if($(event.target).hasClass('num-btn')){
if(check == 1){
str = '';
}
}
check = 2;
//if (checker === 'first') {
str += $(event.target).text();
//firstNumbers.push($(event.target).val())
dis.val(str)
//}else if (checker === 'second'){
// str += $(event.target).val();
// //secondNumbers.push($(event.target).val())
// dis.text(str)
//}
})
// $('.op-btn').on('click', function(event){
// str += $(event.target).val();
// //console.log(str)
// //opO = $(event.target).val();
// //checker = 'second'
// dis.text(str)
// })
//function equal(firstNumbers, opO, secondNumbers){
// console.log(firstNumbers)
// var firstNumber = parseFloat(firstNumbers.join(''));
// console.log(firstNumber)
// var secondNumber = parseFloat(secondNumbers.join(''));
// var result = 0;
// switch(opO){
// case '+':
// result = firstNumber + secondNumber;
// break;
// case '-':
// result = firstNumber - secondNumber;
// break;
// case '*':
// result = firstNumber * secondNumber;
// break;
// case '/':
// if (secondNumber === 0) {
// console.log("we don't do that here");
// $('#img').show();
// $('#calc').hide()
// }else {
// result = firstNumber / secondNumber;
// }
// break;
// case '√':
// result = Math.sqrt(firstNumber);
// break;
// case '^':
// result = Math.pow(firstNumber, secondNumber)
// break;
// }
//dis.text(str);
//return eval(str)
//return result
//}
$('#equal-sign').on('click', function(){
//var outCome = equal(firstNumbers, opO,secondNumbers)
if(dis.val()){
str = dis.val().split(' ').join('')
}
if(str.indexOf('^') != -1){
str = str.replace('^', '**');
}
if(str.indexOf('√') != -1){
str = str.replace('√', '**0.5')
console.log(str)
}
var hasStr = str.match(/[a-z]/g);
console.log(hasStr)
if (hasStr != null) {
console.log(str)
$('#drake').show();
$('#calc').hide()
}else if (eval(str) === 2) {
$('#sbonge-meme').show();
$('#calc').hide()
}else if(eval(str) === Infinity){
$('#black').show();
$('#calc').hide()
}
dis.val(eval(str));
str = eval(str)
check = 1;
//clearAll();
//firstNumbers.push(outCome);
//checker = 'first';
})
// function clearAll() {
// str = ''
// //firstNumbers = [0];
// //secondNumbers = [];
// //checker = 'first';
// //opO = '';
// }
//listen to clear button to clear our str variable
//and display 0
$('#clear-display').on('click',function () {
//clearAll();
str = ''
dis.val(0);
})