-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
49 lines (43 loc) · 1.56 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
const princeBox = document.querySelector("#principal")
const intBox = document.querySelector("#interest")
const numBox = document.querySelector("#ncompounded")
const yearBox = document.querySelector("#time")
const totalSpan = document.querySelector("#balance")
//const button = document.querySelector('input')
//const paragraph = document.querySelector('p')
function computeInterest(){
const principal = princeBox.value
const interest = intBox.value / 100.0
const nCompounded = numBox.value
const time = yearBox.value
const balance = principal*Math.pow((1 + interest/nCompounded), time * nCompounded)
totalSpan.textContent = balance
}
const button = document.querySelector('input');
const paragraph = document.querySelector('p');
button.addEventListener('click', updateButton);
/*
function updateButton() {
if (button.value === 'Start machine') {
button.value = 'Stop machine';
paragraph.textContent = 'The machine has started!';
} else {
button.value = 'Start machine';
paragraph.textContent = 'The machine is stopped.';
}
}*/
function updateButton() {
if (button.value === 'Click me for fun!') {
button.value = 'Hide';
paragraph.textContent = 'Hover over the balance number for a transition';
}
else{
button.value = 'Click me for fun!';
paragraph.textContent = '';
}
}
princeBox.addEventListener('input', computeInterest)
intBox.addEventListener('input', computeInterest)
numBox.addEventListener('input', computeInterest)
yearBox.addEventListener('input', computeInterest)
//button.addEventListener('click', updateButton)