Here is the corrected code:
function convertTime() {
let hours, minutes, ampm;
let military = prompt("Enter military time (hh:mm):");
// Verify input is a valid military time
if (!/^\d{2}:\d{2}$/.test(military)) {
alert(military + " is not a valid time.");
return;
}
// Parse hours and minutes
hours = parseInt(military.split(":")[0]);
minutes = parseInt(military.split(":")[1]);
// Convert to 12-hour format
if (hours == 0) {
hours = 12;
ampm = "AM";
} else if (hours < 12) {
ampm = "AM";
} else if (hours == 12) {
ampm = "PM";
} else {
hours = hours - 12;
ampm = "PM";
}
// Output the converted time
let standard = hours.toString().padStart(2, "0") + ":" + minutes.toString().padStart(2, "0") + " " + ampm;
alert("Standard time: " + standard);
// Ask if the user wants to convert another time
let repeat = prompt("Would you like to convert another time? (y/n)").toLowerCase();
if (repeat == "y") {
convertTime();
}
}
convertTime();