-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculatorscriptapi.js
More file actions
43 lines (35 loc) · 908 Bytes
/
Copy pathcalculatorscriptapi.js
File metadata and controls
43 lines (35 loc) · 908 Bytes
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
function calculate()
{
var inp = document.getElementById("input").value;
var encode = encodeURIComponent(inp);
var address = "http://api.mathjs.org/v4/?expr=" + encode;
$.getJSON(address,
function(data)
{
console.log(data);
document.getElementById("input").value = data;
}
);
}
function add(num)
{
var current = document.getElementById("input").value;
var update = current + num;
document.getElementById("input").value = update;
}
function reset()
{
document.getElementById("input").value = "";
}
function back()
{
var current = document.getElementById("input").value;
var update = current.slice(0,current.length-1);
document.getElementById("input").value = update;
}
input.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("enter").click();
}
});