---
id: 69cfca90e8a0a6d4d6871c50
title: "Challenge 266: Good Day"
challengeType: 28
dashedName: challenge-266
---

# --description--

Given a time string in `"HH:MM"` format (24-hour clock), return:

- `"Good morning"` for times `05:00` to `11:59`
- `"Good afternoon"` for times `12:00` to `17:59`
- `"Good evening"` for times `18:00` to `21:59`
- `"Good night"` for times `22:00` to `04:59`

# --hints--

`getGreeting("06:30")` should return `"Good morning"`.

```js
assert.equal(getGreeting("06:30"), "Good morning");
```

`getGreeting("12:00")` should return `"Good afternoon"`.

```js
assert.equal(getGreeting("12:00"), "Good afternoon");
```

`getGreeting("21:59")` should return `"Good evening"`.

```js
assert.equal(getGreeting("21:59"), "Good evening");
```

`getGreeting("00:01")` should return `"Good night"`.

```js
assert.equal(getGreeting("00:01"), "Good night");
```

`getGreeting("11:30")` should return `"Good morning"`.

```js
assert.equal(getGreeting("11:30"), "Good morning");
```

# --seed--

## --seed-contents--

```js
function getGreeting(time) {

  return time;
}
```

# --solutions--

```js
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';
}
```
