Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Time Converter (24h to 12h) by vvm70
"use strict";
function timeConverter(dayTime) {
let [h, m] = dayTime.split(':');
return `${+(!(+h % 12)) * 12 + +h % 12}:${m} ${+h >= 12 ? 'p.m.' : 'a.m.'}`;
}
var assert = require('assert');
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!");
July 23, 2020