You are viewing a single comment's thread. Return to all comments →
function timeConversion(s) { // Write your code here // take the 12-hour-format AM or PM let timeFormat = s.slice(-2) let hourHand = s.slice(0,2) let minuteHand = s.slice(3,5) let secondsHand = s.slice(6,8) if(timeFormat == "AM" && hourHand == '12'){ let militaryHourHand = Number(hourHand)-12 return 0{minuteHand}:${secondsHand} } else if(timeFormat == 'PM'){ if(hourHand == '01' || hourHand == '02' || hourHand == '03' || hourHand == '04' || hourHand == '05' || hourHand == '06' || hourHand == '07' || hourHand == '01' || hourHand == '08' ||hourHand == '09' || hourHand == '10' || hourHand == '11'){ let militaryHourHand = Number(hourHand) + 12 return ${militaryHourHand}:$`{minuteHand}:${secondsHand}` } else { return{minuteHand}:${secondsHand} } } else { return {minuteHand}:${secondsHand} }
0
{minuteHand}:${secondsHand}
${militaryHourHand}:$`{minuteHand}:${secondsHand}` } else { return
}
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Time Conversion
You are viewing a single comment's thread. Return to all comments →
function timeConversion(s) { // Write your code here // take the 12-hour-format AM or PM let timeFormat = s.slice(-2) let hourHand = s.slice(0,2) let minuteHand = s.slice(3,5) let secondsHand = s.slice(6,8) if(timeFormat == "AM" && hourHand == '12'){ let militaryHourHand = Number(hourHand)-12 return
0
{minuteHand}:${secondsHand}
} else if(timeFormat == 'PM'){ if(hourHand == '01' || hourHand == '02' || hourHand == '03' || hourHand == '04' || hourHand == '05' || hourHand == '06' || hourHand == '07' || hourHand == '01' || hourHand == '08' ||hourHand == '09' || hourHand == '10' || hourHand == '11'){ let militaryHourHand = Number(hourHand) + 12 return${militaryHourHand}:$`{minuteHand}:${secondsHand}` } else { return
{minuteHand}:${secondsHand}
}} else { return
{minuteHand}:${secondsHand}
}}