formulaegyjs/main.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-04-13 09:17:52 +00:00
$(document).ready(function () {
$('.navbar-nav li').click(function (x) {
2023-04-13 10:18:48 +00:00
$('.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,
},
}
2023-04-13 09:17:52 +00:00
function showCircuit() {
2023-04-13 10:18:48 +00:00
/** @type {HTMLImageElement} */
const img = document.getElementById('circuitimage-img')
/** @type {HTMLSelectElement} */
const circuit = document.getElementById('circuit')
img.src = './img/' + circuits[circuit.value].img
2023-04-13 09:17:52 +00:00
}
//---------------------------------------------------------
function calculate() {
2023-04-13 10:18:48 +00:00
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'
2023-04-13 09:17:52 +00:00
}