Bug hunt: fix code you did not write

PremiumAdvanced25 min3 exercises

Most code you will ever fix was written by someone else. This lesson is three JavaScript programs that are broken on purpose, in ways real ones break. None of them throws an error. They run, print something, and the something is wrong. That is what makes JavaScript bugs sneaky: the language tries very hard to keep going.

A process that works:

Watch out for the three classics: + gluing strings instead of adding numbers, arrow functions with curly braces needing a return, and arrays changing under a loop that is walking through them.

The rest of this lesson is Premium

Three broken JavaScript programs to repair: numbers that are secretly strings, an arrow function that returns nothing, and a loop that skips items.

Module
JavaScript + HTML/CSS Advanced: Connect JavaScript to the page: change the DOM, react to events and read forms, then fix three programs that are broken on purpose.
Challenges
  • The total that is not a number
  • Doubling into nothing
  • The loop that skips

First challenge: The total that is not a number

The prices came from a form, so they are strings. This should print Total: 9.5 and prints something very different. Fix it.

£7.99 a month, or £59 a year

Premium opens every Core and Advanced lesson in all four tracks, with the editor, checker and hints, plus the bigger projects. Cancel any time.

See Premium

Or keep going for free: JavaScript + HTML/CSS Foundations and the playground are free for good.