generated from Migracode-Barcelona/cyf-blocks-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
59 lines (47 loc) · 1.6 KB
/
script.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
/* paste the JavaScript code from the 'Generated Code' section of the CYF Blocks editor here */
var y, x, input, earnvalues, expenses, balance;
function getNumberOrString(value) {
// Convert a string value to a number if possible
let number_value = Number(value);
if (Number.isNaN(number_value)) {
return value
} else {
return number_value
}
}
// Describe this function...
function sum(y, x) {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
if (expenses) {
return;
}
}
earnvalues = [0];
expenses = [0];
balance = [0, 0];
document.getElementById('dis').addEventListener('click', (event) => {
input = getNumberOrString(document.getElementById('text').value);
balance.unshift(input);
if (input >= 0) {
let element_list = document.getElementById('list');
earnvalues.unshift(input);
let new_li = document.createElement('li');
new_li.innerText = input;
element_list.appendChild(new_li);
let element_earn = document.getElementById('earn');
element_earn.innerText = earnvalues.reduce((a,b) => a+b, 0);
} else if (input <= 0) {
let element_liste = document.getElementById('liste');
expenses.unshift(input);
let new_li2 = document.createElement('li');
new_li2.innerText = input;
element_liste.appendChild(new_li2);
let element_expen = document.getElementById('expen');
element_expen.innerText = expenses.reduce((a,b) => a+b, 0);
}
});
input;
document.getElementById('balance').addEventListener('click', (event) => {
let element_total = document.getElementById('total');
element_total.innerText = balance.reduce((a,b) => a+b, 0);
});