Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
ifless solution in Clear category for [old] Time Converter (24h to 12h) by vincent.tscherter
"use strict";
function timeConverter(dayTime) {
let [hours, minutes, ampm] = dayTime.split(":");
ampm = +hours < 12 ? 'a.m.' : 'p.m.';
hours = +hours % 12 || 12;
return `${hours}:${minutes} ${ampm}`;
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(timeConverter('12:30'))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(timeConverter('12:30'), '12:30 p.m.')
assert.equal(timeConverter('09:00'), '9:00 a.m.')
assert.equal(timeConverter('23:15'), '11:15 p.m.')
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
May 29, 2018