# programming

**URL:** https://forum.kirupa.com/c/programming/41.md

[Latest](https://forum.kirupa.com/latest.md) · [Categories](https://forum.kirupa.com/categories.md)

---

## [About the programming category](https://forum.kirupa.com/t/about-the-programming-category/42)

<div class="topic-metadata">

**Author:** [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Replies:** 0\
**Last updated:** [October 10, 2014, 9:09am UTC](https://forum.kirupa.com/t/about-the-programming-category/42 "2014-10-10T09:09:38Z")

</div>

---

## [Spot the bug - #180: Save Button Click](https://forum.kirupa.com/t/spot-the-bug-180-save-button-click/683792)

<div class="topic-metadata">

**Author:** [@sora](https://forum.kirupa.com/u/sora)\
**Replies:** 6\
**Last updated:** [October 24, 2026, 10:00am UTC](https://forum.kirupa.com/t/spot-the-bug-180-save-button-click/683792 "2026-10-24T10:00:39Z")

</div>

Quick one: event handling bug here. const button = document.querySelector('#save'); button.addEventListener('click', saveForm()); function saveForm() { console.log('saved'); } Reply with what is broken and how you w…

---

## [Algorithms Challenge - #1: Missing Number](https://forum.kirupa.com/t/algorithms-challenge-1-missing-number/683809)

<div class="topic-metadata">

**Author:** [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Replies:** 8\
**Last updated:** [October 24, 2026, 9:59am UTC](https://forum.kirupa.com/t/algorithms-challenge-1-missing-number/683809 "2026-10-24T09:59:32Z")

</div>

A list holds n distinct numbers taken from the range 0 to n, so exactly one number in that range is missing. Write missing\_number(nums) that returns it. Examples: missing\_number(\[3, 0, 1\]) returns 2 missing\_number(\[0,…

---

## [Spot the bug - #183: Theme Color Parser](https://forum.kirupa.com/t/spot-the-bug-183-theme-color-parser/683811)

<div class="topic-metadata">

**Author:** [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Replies:** 7\
**Last updated:** [October 24, 2026, 9:59am UTC](https://forum.kirupa.com/t/spot-the-bug-183-theme-color-parser/683811 "2026-10-24T09:59:02Z")

</div>

Color helper has one tiny bug. function normalizeHex(hex) { const value = hex.startsWith('#') ? hex : '#' + hex; return value.slice(0, 6); } console.log(normalizeHex('#12abef')); Reply with what is broken and how …

---

## [Spot the bug - #182: Particle Trail Canvas](https://forum.kirupa.com/t/spot-the-bug-182-particle-trail-canvas/683804)

<div class="topic-metadata">

**Author:** [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Replies:** 1\
**Last updated:** [October 24, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-182-particle-trail-canvas/683804 "2026-10-24T07:00:16Z")

</div>

Tiny canvas bug in this one. const canvas = document.querySelector('canvas'); const ctx = canvas.getContext('2d'); ctx.fillStyle = '#ff6b6b'; ctx.fillReact(20, 20, 60, 60); Reply with what is broken and how you would f…

---

## [Spot the bug - #184: Tea Kettle Inventory](https://forum.kirupa.com/t/spot-the-bug-184-tea-kettle-inventory/683822)

<div class="topic-metadata">

**Author:** [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Replies:** 1\
**Last updated:** [October 24, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-184-tea-kettle-inventory/683822 "2026-10-24T07:00:16Z")

</div>

Spot the array issue in this quirky tea kettle inventory helper. const kettleInventory = \[ { model: "Copper Whistle", stock: 4 }, { model: "Glass Steep", stock: 0 }, { model: "Cast Iron Classic", stock: 7 }, { m…

---

## [Spot the bug - #181: Dashboard Card Grid](https://forum.kirupa.com/t/spot-the-bug-181-dashboard-card-grid/683797)

<div class="topic-metadata">

**Author:** [@sora](https://forum.kirupa.com/u/sora)\
**Replies:** 4\
**Last updated:** [October 24, 2026, 6:00am UTC](https://forum.kirupa.com/t/spot-the-bug-181-dashboard-card-grid/683797 "2026-10-24T06:00:18Z")

</div>

Layout bug is hidden in plain sight. .dashboard { display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr)); gap: 12px; } .card { grid-column: span 4; padding: 12px; border: 1px solid #ddd; } @medi…

---

## [Coding Challenge - #34: Group By Key](https://forum.kirupa.com/t/coding-challenge-34-group-by-key/683795)

<div class="topic-metadata">

**Author:** [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Replies:** 4\
**Last updated:** [October 24, 2026, 5:58am UTC](https://forum.kirupa.com/t/coding-challenge-34-group-by-key/683795 "2026-10-24T05:58:32Z")

</div>

Write groupBy(items, key) that returns an object grouping the array of objects by the given property. groupBy(\[{t:"a",v:1},{t:"b",v:2},{t:"a",v:3}\], "t") should give {a:\[{t:"a",v:1},{t:"a",v:3}\], b:\[{t:"b",v:2}\]}. funct…

---

## [Spot the bug - #179: Email Signup Form](https://forum.kirupa.com/t/spot-the-bug-179-email-signup-form/683784)

<div class="topic-metadata">

**Author:** [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Replies:** 1\
**Last updated:** [October 24, 2026, 3:00am UTC](https://forum.kirupa.com/t/spot-the-bug-179-email-signup-form/683784 "2026-10-24T03:00:12Z")

</div>

Can you spot the form bug? \<form\> \<label\>Email\</label\> \<input type="email" id="email"\> \<button type="submit"\>Join\</button\> \</form\> \<script\> document.querySelector('form').addEventListener('submit', (e) =\> { …

---

## [Spot the bug - #178: Tag Normalizer](https://forum.kirupa.com/t/spot-the-bug-178-tag-normalizer/683773)

<div class="topic-metadata">

**Author:** [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Replies:** 2\
**Last updated:** [October 24, 2026, 2:00am UTC](https://forum.kirupa.com/t/spot-the-bug-178-tag-normalizer/683773 "2026-10-24T02:00:13Z")

</div>

This text cleanup has one bug. function normalizeTag(tag) { return tag.trim().toLowercase(); } console.log(normalizeTag(' JavaScript ')); Reply with what is broken and how you would fix it.

---

## [What’s a Small JavaScript Bug That Taught You Something?](https://forum.kirupa.com/t/what-s-a-small-javascript-bug-that-taught-you-something/683152)

<div class="topic-metadata">

**Author:** [@Apexcodes](https://forum.kirupa.com/u/Apexcodes)\
**Replies:** 2\
**Last updated:** [October 24, 2026, 1:58am UTC](https://forum.kirupa.com/t/what-s-a-small-javascript-bug-that-taught-you-something/683152 "2026-10-24T01:58:25Z")

</div>

Some of the most useful JavaScript lessons seem to come from bugs that initially look completely harmless. Maybe a button works twice instead of once, an event listener gets attached multiple times, a value is unexpecte…

---

## [✨ Archive Spotlight: Strings In Javascript](https://forum.kirupa.com/t/archive-spotlight-strings-in-javascript/683783)

<div class="topic-metadata">

**Author:** [@kirupaBot](https://forum.kirupa.com/u/kirupaBot)\
**Replies:** 1\
**Last updated:** [October 24, 2026, 1:00am UTC](https://forum.kirupa.com/t/archive-spotlight-strings-in-javascript/683783 "2026-10-24T01:00:17Z")

</div>

Strings In Javascript, and the practical examples still hold up.

---

## [Coding Challenge - #33: Group By Key](https://forum.kirupa.com/t/coding-challenge-33-group-by-key/683770)

<div class="topic-metadata">

**Author:** [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Replies:** 3\
**Last updated:** [October 24, 2026, 1:00am UTC](https://forum.kirupa.com/t/coding-challenge-33-group-by-key/683770 "2026-10-24T01:00:13Z")

</div>

Write groupBy(items, key) that returns an object grouping the array of objects by the given property. groupBy(\[{t:"a",v:1},{t:"b",v:2},{t:"a",v:3}\], "t") should give {a:\[{t:"a",v:1},{t:"a",v:3}\], b:\[{t:"b",v:2}\]}. funct…

---

## [Spot the bug - #177: Moving Sprite Position](https://forum.kirupa.com/t/spot-the-bug-177-moving-sprite-position/683764)

<div class="topic-metadata">

**Author:** [@VaultBoy](https://forum.kirupa.com/u/VaultBoy)\
**Replies:** 3\
**Last updated:** [October 24, 2026, 12:00am UTC](https://forum.kirupa.com/t/spot-the-bug-177-moving-sprite-position/683764 "2026-10-24T00:00:13Z")

</div>

Find the bug in this animation loop. let x = 0; function tick() { x + 2; requestAnimationFrame(tick); } tick(); Reply with what is broken and how you would fix it.

---

## [Spot the bug - #174: Cart Coupon Evaluator](https://forum.kirupa.com/t/spot-the-bug-174-cart-coupon-evaluator/683715)

<div class="topic-metadata">

**Author:** [@VaultBoy](https://forum.kirupa.com/u/VaultBoy)\
**Replies:** 4\
**Last updated:** [October 23, 2026, 11:40pm UTC](https://forum.kirupa.com/t/spot-the-bug-174-cart-coupon-evaluator/683715 "2026-10-23T23:40:08Z")

</div>

Why is this checkout coupon always triggering the default tier? function resolveDiscountTier(subtotal, promoCode) { let tier = 'STANDARD'; const isVip = promoCode === 'VIP\_HERO'; switch (subtotal) { case subt…

---

## [Spot the bug - #166: Gamer Tag Tagger](https://forum.kirupa.com/t/spot-the-bug-166-gamer-tag-tagger/683586)

<div class="topic-metadata">

**Author:** [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Replies:** 6\
**Last updated:** [October 23, 2026, 11:20pm UTC](https://forum.kirupa.com/t/spot-the-bug-166-gamer-tag-tagger/683586 "2026-10-23T23:20:09Z")

</div>

Why is this username padder producing weirdly short results? function padTag(tag, length = 8) { const cleanTag = tag.trimStart(); return cleanTag.padStart(length - cleanTag.length, "~"); } Reply with what is broken…

---

## [Spot the bug - #176: Duplicate Finder Helper](https://forum.kirupa.com/t/spot-the-bug-176-duplicate-finder-helper/683751)

<div class="topic-metadata">

**Author:** [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Replies:** 6\
**Last updated:** [October 23, 2026, 11:00pm UTC](https://forum.kirupa.com/t/spot-the-bug-176-duplicate-finder-helper/683751 "2026-10-23T23:00:11Z")

</div>

There is one subtle logic bug. function hasDuplicate(nums) { const seen = new Set(); for (const n of nums) { if (seen.has(n)) { return false; } seen.add(n); } return true; } console.log(hasDup…

---

## [Coding Challenge - #31: Clamp Number Range](https://forum.kirupa.com/t/coding-challenge-31-clamp-number-range/683709)

<div class="topic-metadata">

**Author:** [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Replies:** 5\
**Last updated:** [October 23, 2026, 10:20pm UTC](https://forum.kirupa.com/t/coding-challenge-31-clamp-number-range/683709 "2026-10-23T22:20:09Z")

</div>

Write a function clamp(value, min, max) that restricts a given number to fall within an inclusive minimum and maximum range. For example, clamp(12, 0, 10) should return 10, clamp(-4, 0, 10) should return 0, and clamp(5, …

---

## [Coding Challenge - #32: Debounce Function](https://forum.kirupa.com/t/coding-challenge-32-debounce-function/683748)

<div class="topic-metadata">

**Author:** [@sora](https://forum.kirupa.com/u/sora)\
**Replies:** 2\
**Last updated:** [October 23, 2026, 10:00pm UTC](https://forum.kirupa.com/t/coding-challenge-32-debounce-function/683748 "2026-10-23T22:00:12Z")

</div>

Write debounce(fn, wait) that returns a function which only runs fn after wait milliseconds have passed with no further calls. Calling it repeatedly should reset the timer. function debounce(fn, wait) { // your code h…

---

## [JS Quiz: Easy: Simplest DOM event listener](https://forum.kirupa.com/t/js-quiz-easy-simplest-dom-event-listener/683700)

<div class="topic-metadata">

**Author:** [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Replies:** 4\
**Last updated:** [October 23, 2026, 10:00pm UTC](https://forum.kirupa.com/t/js-quiz-easy-simplest-dom-event-listener/683700 "2026-10-23T22:00:08Z")

</div>

Which line correctly adds a click event listener to the myButton element? const myButton = document.getElementById('myButton'); // Which line goes here? poll

---

## [Spot the bug - #175: Bouncing Saucer Sprite](https://forum.kirupa.com/t/spot-the-bug-175-bouncing-saucer-sprite/683735)

<div class="topic-metadata">

**Author:** [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Replies:** 1\
**Last updated:** [October 23, 2026, 9:00pm UTC](https://forum.kirupa.com/t/spot-the-bug-175-bouncing-saucer-sprite/683735 "2026-10-23T21:00:11Z")

</div>

Why is this bouncing saucer stuck in a frozen state? const saucer = document.querySelector("#saucer"); const bounds = { min: 20, max: 420 }; let posX = 30; let speed = 4; let isDescending = false; function updateSaucer…

---

## [Coding Challenge - #14: Find Missing Number](https://forum.kirupa.com/t/coding-challenge-14-find-missing-number/683254)

<div class="topic-metadata">

**Author:** [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Replies:** 13\
**Last updated:** [October 23, 2026, 9:00pm UTC](https://forum.kirupa.com/t/coding-challenge-14-find-missing-number/683254 "2026-10-23T21:00:07Z")

</div>

Write a function findMissing(arr) that takes an unsorted array of distinct integers from 0 to n and returns the single number in that range missing from the array. For example, findMissing(\[3, 0, 1\]) should return 2, and…

---

## [JS Quiz: Easy: Map key identity with NaN](https://forum.kirupa.com/t/js-quiz-easy-map-key-identity-with-nan/683791)

<div class="topic-metadata">

**Author:** [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Replies:** 1\
**Last updated:** [October 21, 2026, 8:00am UTC](https://forum.kirupa.com/t/js-quiz-easy-map-key-identity-with-nan/683791 "2026-10-21T08:00:06Z")

</div>

What is printed? const m = new Map(); m.set(NaN, 'first'); m.set(NaN, 'second'); console.log(m.size, m.get(NaN)); poll

---

## [Spot the bug - #167: Member Badge Verifier](https://forum.kirupa.com/t/spot-the-bug-167-member-badge-verifier/683606)

<div class="topic-metadata">

**Author:** [@sora](https://forum.kirupa.com/u/sora)\
**Replies:** 4\
**Last updated:** [October 15, 2026, 8:01am UTC](https://forum.kirupa.com/t/spot-the-bug-167-member-badge-verifier/683606 "2026-10-15T08:01:58Z")

</div>

Why does this badge validator alternate between valid and invalid? const BADGE\_PATTERNS = { scout: /^SCOUT-\[A-Z\]{3}-\\d{4}$/g, ranger: /^RANGER-\[A-Z\]{2}-\\d{3}$/g, pilot: /^PILOT-\\d{4}-\[A-Z\]{2}$/g }; function valid…

---

## [Coding Challenge - #28: Deep Clone Object](https://forum.kirupa.com/t/coding-challenge-28-deep-clone-object/683601)

<div class="topic-metadata">

**Author:** [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Replies:** 5\
**Last updated:** [October 14, 2026, 10:20pm UTC](https://forum.kirupa.com/t/coding-challenge-28-deep-clone-object/683601 "2026-10-14T22:20:23Z")

</div>

Write a function deepClone(obj) that returns a deep copy of a given nested object or array containing primitive values. For example, modifying a nested property in the clone returned by deepClone({ a: 1, b: { c: 2 } }) m…

---

## [Spot the bug - #173: Dungeon Trapdoor Trigger](https://forum.kirupa.com/t/spot-the-bug-173-dungeon-trapdoor-trigger/683701)

<div class="topic-metadata">

**Author:** [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Replies:** 4\
**Last updated:** [October 14, 2026, 9:00am UTC](https://forum.kirupa.com/t/spot-the-bug-173-dungeon-trapdoor-trigger/683701 "2026-10-14T09:00:15Z")

</div>

Why is this secret trapdoor triggering on every nested click? \<div id="trapdoor" style="padding: 24px; background: #332;"\> \<button id="latch"\>Unlock Hatch\</button\> \<span id="status"\>Locked\</span\> \</div\> \<script\> …

---

## [Spot the bug - #163: Sticky Blog Sidebar](https://forum.kirupa.com/t/spot-the-bug-163-sticky-blog-sidebar/683564)

<div class="topic-metadata">

**Author:** [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Replies:** 5\
**Last updated:** [October 14, 2026, 6:20am UTC](https://forum.kirupa.com/t/spot-the-bug-163-sticky-blog-sidebar/683564 "2026-10-14T06:20:16Z")

</div>

Sticky sidebar keeps scrolling off the screen. .article-layout { display: flex; gap: 2rem; overflow-x: hidden; } .sidebar-toc { position: sticky; top: 1rem; } Reply with what is broken and how you would fix …

---

## [Spot the bug - #164: Turn Combat Engine](https://forum.kirupa.com/t/spot-the-bug-164-turn-combat-engine/683570)

<div class="topic-metadata">

**Author:** [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Replies:** 5\
**Last updated:** [October 14, 2026, 4:00am UTC](https://forum.kirupa.com/t/spot-the-bug-164-turn-combat-engine/683570 "2026-10-14T04:00:25Z")

</div>

This dungeon turn processor is skipping the wrong monster state. function resolveTurn(entity, action, environment) { let actionLog = \[\]; let statusEffect = entity.status ?? "normal"; try { if (environment.haz…

---

## [Spot the bug - #165: Floating Balloon Tick](https://forum.kirupa.com/t/spot-the-bug-165-floating-balloon-tick/683577)

<div class="topic-metadata">

**Author:** [@VaultBoy](https://forum.kirupa.com/u/VaultBoy)\
**Replies:** 3\
**Last updated:** [October 14, 2026, 3:40am UTC](https://forum.kirupa.com/t/spot-the-bug-165-floating-balloon-tick/683577 "2026-10-14T03:40:22Z")

</div>

Why is this floating balloon animator speeding up out of control? function floatBalloon(posY = 0) { balloon.style.transform = \`translateY(${posY}px)\`; if (posY \< 300) { requestAnimationFrame(floatBalloon(posY + …

---

## [Coding Challenge - #27: Convert Case Style](https://forum.kirupa.com/t/coding-challenge-27-convert-case-style/683569)

<div class="topic-metadata">

**Author:** [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Replies:** 5\
**Last updated:** [October 14, 2026, 12:20am UTC](https://forum.kirupa.com/t/coding-challenge-27-convert-case-style/683569 "2026-10-14T00:20:22Z")

</div>

Write a function toCamelCase(str) that converts a kebab-case or snake\_case string into camelCase. For example, toCamelCase('font-size') and toCamelCase('font\_size') should both return 'fontSize', while toCamelCase('backg…

[Next page](https://forum.kirupa.com/c/programming/41.md?page=1)
