window.addEventListener("load", function () { getTime(); }); let fast = 30; let normal = 24; let slow = 18; function calculateDays(speed, distance){ let time = distance / speed; let days = parseInt(time.toString().split(".")[0]); let hours = (time % 1 * 24).toFixed(0); if (days == 1 && hours 1) { return days.toString() + " day and " + hours.toString() + " hours" } else if (days == 1 && hours == 0) { return days.toString() + " day" } else if (days 1 && hours == 0) { return days.toString() + " days" } else if (days == 0 && hours == 1) { return hours.toString() + " hour" } else if (days == 0 && hours 1) { return hours.toString() + " hours" } else if (days == 1 && hours == 1) { return days.toString() + " day and " + hours.toString() + " hour" } else if (days 1 && hours == 1) { return days.toString() + " days and " + hours.toString() + " hour" } else { return days.toString() + " days and " + hours.toString() + " hours" } } function getTime(){ let speed = eval(document.getElementById("speed").value); let distance = parseInt(document.getElementById("miles").value); document.getElementById("time").innerHTML = calculateDays(speed, distance); } Travel Speed Slow Normal Fast Miles Time: