समस्या
हमें एक जावास्क्रिप्ट फ़ंक्शन लिखना है जो सेकंड की संख्या लेता है और उन सेकंड में निहित घंटों और मिनटों की संख्या लौटाता है।
इनपुट
const seconds = 3601;
आउटपुट
const output = "1 hour(s) and 0 minute(s)";
उदाहरण
निम्नलिखित कोड है -
const seconds = 3601;
const toTime = (seconds = 60) => {
const hR = 3600;
const mR = 60;
let h = parseInt(seconds / hR);
let m = parseInt((seconds - (h * 3600)) / mR);
let res = '';
res += (`${h} hour(s) and ${m} minute(s)`)
return res;
};
console.log(toTime(seconds)); आउटपुट
"1 hour(s) and 0 minute(s)"