-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
89 lines (70 loc) · 2.61 KB
/
index.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
// index.js
const ipc = require('electron').ipcRenderer;
var java = require("java");
document.getElementById('nine').onclick = function() {
document.getElementById('screen').innerHTML += '9';
}
document.getElementById('eight').onclick = function() {
document.getElementById('screen').innerHTML += '8';
}
document.getElementById('seven').onclick = function() {
document.getElementById('screen').innerHTML += '7';
}
document.getElementById('six').onclick = function() {
document.getElementById('screen').innerHTML += '6';
}
document.getElementById('five').onclick = function() {
document.getElementById('screen').innerHTML += '5';
}
document.getElementById('four').onclick = function() {
document.getElementById('screen').innerHTML += '4';
}
document.getElementById('three').onclick = function() {
document.getElementById('screen').innerHTML += '3';
}
document.getElementById('two').onclick = function() {
document.getElementById('screen').innerHTML += '2';
}
document.getElementById('one').onclick = function() {
document.getElementById('screen').innerHTML += '1';
}
document.getElementById('zero').onclick = function() {
document.getElementById('screen').innerHTML += '0';
}
document.getElementById('comma').onclick = function() {
document.getElementById('screen').innerHTML += '.';
}
document.getElementById('add').onclick = function() {
if(isScreenValueOk(document.getElementById('screen').innerHTML))
document.getElementById('screen').innerHTML += '+';
}
document.getElementById('sub').onclick = function() {
if(isScreenValueOk(document.getElementById('screen').innerHTML))
document.getElementById('screen').innerHTML += '-';
}
document.getElementById('div').onclick = function() {
if(isScreenValueOk(document.getElementById('screen').innerHTML))
document.getElementById('screen').innerHTML += '/';
}
document.getElementById('mul').onclick = function() {
if(isScreenValueOk(document.getElementById('screen').innerHTML))
document.getElementById('screen').innerHTML += '*';
}
document.getElementById('result').onclick = function() {
ipc.send('calculate', document.getElementById('screen').innerHTML);
}
document.getElementById('clear').onclick = function() {
document.getElementById('screen').innerHTML = '';
// write this on Browser console ....
console.log("Clear ...");
}
ipc.on('updateResult', function(event, data){
document.getElementById('screen').innerHTML = data;
});
function isScreenValueOk(screenValue) {
stringLength = screenValue.length;
if(stringLength == 0)
return false;
else
return Number.isInteger(parseInt(screenValue.substring(stringLength-1, stringLength)));
}