scrimba
Note at 0:00
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Note at 0:00
Expand for more info
index.js
run
preview
console
const speedometer = document.getElementById("speedometer")
const select = document.getElementById("select")
const time = document.getElementById("time")
const btnCalculate = document.getElementById("btnCalculate")
let currentLocation = ""
let timeTaken = 0

let destination = [
{
name: "Munich",
distanceFromPrevDestination: 2892
},
{
name: "Kiev",
distanceFromPrevDestination: 1111
},
{
name: "Ulaanbaatar",
distanceFromPrevDestination: 5324
},
{
name: "Sydney",
distanceFromPrevDestination: 5458
},
{
name: "Tijuana",
distanceFromPrevDestination: 6531
},
{
name: "Chicago",
distanceFromPrevDestination: 1729
}
]

function calculateSpeed() {
let speed = 0
currentLocation = select.value
let distance = destination.find(obj => obj.name === currentLocation).distanceFromPrevDestination
timeTaken = time.value

if (timeTaken === '0') {
speed = 0
} else {
speed = parseInt(distance) / parseInt(timeTaken)
}

speedometer.innerText = `${speed} reindeer speed`
// Task:
// - Retrieve distance from previous destination from array of objects.
// - Calculate speed and round speed to an integer (whole number).
// - Display speed in speedometer paragraph.

}

btnCalculate.addEventListener('click',calculateSpeed)

// Stretch goals:
// - Calculate average overall speed.
// - Display location as North Pole on pageload.
Console
/index.html
LIVE