Journal

1 post
function calculate() { const distance = document.getElementById('distance').value; const hours = document.getElementById('hours').value; const minutes = document.getElementById('minutes').value; const seconds = document.getElementById('seconds').value; const totalSeconds = (+hours * 3600) + (+minutes * 60) + (+seconds); const totalHours = totalSeconds / 3600; if (totalSeconds > 0 && distance > 0) { const speed = (distance / 1000) / totalHours; const pace = totalSeconds / (distance / 1000) / 60; document.getElementById('speed').innerText = speed.toFixed(2); document.getElementById('pace').innerText = Math.floor(pace) + ':' + ('0' + Math.round((pace - Math.floor(pace)) * 60)).slice(-2); } else { alert("Veuillez entrer une distance et un temps valides."); } }