$(document).ready(function () { $('.navbar-nav li').click(function (x) { $('.navbar-nav li').removeClass('active') $(event.target).parent().addClass('active') }) }) const circuits = { 'HUN': { img: 'hungaroring.jpg', l: 4.381, }, 'MON': { img: 'monaco.jpg', l: 3.337, }, 'BEL': { img: 'spa.jpg', l: 7.004, }, 'ITA': { img: 'monza.jpg', l: 5.793, }, } function showCircuit() { /** @type {HTMLImageElement} */ const img = document.getElementById('circuitimage-img') /** @type {HTMLSelectElement} */ const circuit = document.getElementById('circuit') img.src = './img/' + circuits[circuit.value].img } //--------------------------------------------------------- function calculate() { showCircuit() /** @type {HTMLSelectElement} */ const circuit = document.getElementById('circuit') /** @type {HTMLInputElement} */ const laptime = document.getElementById('laptime') /** @type {HTMLInputElement} */ const output = document.getElementById('averagespeed') /** @type {number} */ if (!circuit.value || !laptime.value) { return } const l = circuits[circuit.value].l const t = laptime.valueAsNumber output.value = Math.round(l / (t / 3600)) + ' km/h' }