-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
40 lines (30 loc) · 1.1 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
let imperialUnits = document.getElementById("imperial-distance")
let metricUnits = document.getElementById("metric-distance")
function updateMiles() {
let currentMiles = parseFloat(imperialUnits.textContent)
metricUnits.textContent = (currentMiles / 0.621371).toFixed(2)
}
function updateKilometers() {
let currentKilometers = parseFloat(metricUnits.textContent)
imperialUnits.textContent = (currentKilometers * 0.621371).toFixed(2)
}
function addMiles(miles) {
let currentMiles = parseInt(imperialUnits.textContent)
imperialUnits.textContent = currentMiles + miles
updateMiles()
}
function subtractMiles(miles) {
let currentMiles = parseInt(imperialUnits.textContent)
imperialUnits.textContent = currentMiles + miles
updateMiles()
}
function addKilometers(kilometers) {
let currentKilometers = parseInt(metricUnits.textContent)
metricUnits.textContent = currentKilometers + kilometers
updateKilometers()
}
function subtractKilometers(kilometers) {
let currentKilometers = parseInt(metricUnits.textContent)
metricUnits.textContent = currentKilometers + kilometers
updateKilometers()
}