dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.4 KiB
1.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69cfca90e8a0a6d4d6871c50 | Challenge 266: Good Day | 28 | challenge-266 |
--description--
Given a time string in "HH:MM" format (24-hour clock), return:
"Good morning"for times05:00to11:59"Good afternoon"for times12:00to17:59"Good evening"for times18:00to21:59"Good night"for times22:00to04:59
--hints--
getGreeting("06:30") should return "Good morning".
assert.equal(getGreeting("06:30"), "Good morning");
getGreeting("12:00") should return "Good afternoon".
assert.equal(getGreeting("12:00"), "Good afternoon");
getGreeting("21:59") should return "Good evening".
assert.equal(getGreeting("21:59"), "Good evening");
getGreeting("00:01") should return "Good night".
assert.equal(getGreeting("00:01"), "Good night");
getGreeting("11:30") should return "Good morning".
assert.equal(getGreeting("11:30"), "Good morning");
--seed--
--seed-contents--
function getGreeting(time) {
return time;
}
--solutions--
function getGreeting(time) {
const [hours, minutes] = time.split(':').map(Number);
const total = hours * 60 + minutes;
if (total >= 300 && total < 720) return 'Good morning';
if (total >= 720 && total < 1080) return 'Good afternoon';
if (total >= 1080 && total < 1320) return 'Good evening';
return 'Good night';
}