-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (48 loc) · 1.71 KB
/
app.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
console.log('working')
const amountOfCoins = document.querySelector('#amountOfCoins')
const averageCost = document.querySelector('#averageCost')
const currentPrice = document.querySelector('#currentPrice')
const total = document.querySelector('.totals')
const calculate = document.querySelector('.calculate')
const reset = document.querySelector('.reset')
const totalAvgPriceSpan = document.querySelector('#totalAveragePrice')
const totalCurrentPriceSpan = document.querySelector('#totalCurrentPrice')
const currentProfitSpan = document.querySelector('#currentProfit')
let numberOfCoins = 0
let avgCost = 0
let currentCoinPrice = 0
let totalAvg = 0
let totalCurrent = 0
amountOfCoins.addEventListener('keyup', e => {
numberOfCoins = e.target.value
})
averageCost.addEventListener('keyup', e => {
avgCost = e.target.value
})
currentPrice.addEventListener('keyup', e => {
currentCoinPrice = e.target.value
})
calculate.addEventListener('click', e => {
e.preventDefault()
total.style.display = 'flex'
totalAvgPriceSpan.textContent = Math.floor(getTotalAvg(numberOfCoins, avgCost))
totalCurrentPriceSpan.textContent = Math.floor(getTotalCurrentPrice(numberOfCoins, currentCoinPrice))
currentProfitSpan.textContent = Math.floor(totalCurrent - totalAvg)
})
reset.addEventListener('click', e => {
e.preventDefault()
total.style.display = 'none'
amountOfCoins.value = ' '
currentPrice.value = ' '
averageCost.value = ' '
})
const getTotalAvg = (numCoins, avgCost) => {
let result = numCoins * avgCost
totalAvg = result
return result
}
const getTotalCurrentPrice = (numCoins, currentCoinValue) => {
let result = numCoins * currentCoinValue
totalCurrent = result
return result
}