# Spot the bug - #143: Weather Bot Attire

**URL:** <https://forum.kirupa.com/t/spot-the-bug-143-weather-bot-attire/683361>\
**Category:** web dev\
**Created:** [September 13, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-143-weather-bot-attire/683361 "2026-09-13T07:00:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HariSeldon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hariseldon/32/31261_2.png) [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Post date:** [September 13, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-143-weather-bot-attire/683361/1 "2026-09-13T07:00:14Z")

</div>

Why does my weather bot always suggest an umbrella?

```js
function getAttire(forecast) {
  switch (forecast) {
    case "rainy":
      return "bring umbrella";
    case "snowy":
    case "hailing":
    default:
      return "wear coat";
    case "sunny":
      return "wear sunglasses";
  }
}

```

Reply with what is broken and how you would fix it.

---

<div class="post-metadata">

**Author:** ![ArthurDent](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/arthurdent/32/31262_2.png) [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Post date:** [September 14, 2026, 7:20am UTC](https://forum.kirupa.com/t/spot-the-bug-143-weather-bot-attire/683361/2 "2026-09-14T07:20:20Z")

</div>

The `default` case is in the wrong position. It will always catch anything not explicitly `rainy` before `snowy`, `hailing`, or `sunny` can be evaluated. Move `default` to the very end of the `switch` block.

---

<div class="post-metadata">

**Author:** ![HariSeldon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hariseldon/32/31261_2.png) [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Post date:** [September 14, 2026, 8:00am UTC](https://forum.kirupa.com/t/spot-the-bug-143-weather-bot-attire/683361/3 "2026-09-14T08:00:18Z")

</div>

**Spot the Bug answer:** The default case is positioned incorrectly, making it unreachable for most forecasts.

**The fix:**  
Move the default case to the end of the switch statement.

**Why:**  
In JavaScript switch statements, once a case matches or the default case is hit, execution continues until a break statement is encountered or the end of the switch block is reached. With ‘default’ placed before ‘sunny’, any forecast not ‘rainy’, ‘snowy’, or ‘hailing’ will hit ‘default’ and return ‘wear coat’ before the ‘sunny’ case can be evaluated.

**First-answer leaderboard**

1. @Apexcodes - 6 (firsts) 🏆
2. @kirupa - 6 (firsts) 🏆
3. @emmawalter5 - 5 (firsts)
4. @adnanahmed - 2 (firsts)
