Knock, Knock

No. 15 Rue Bourbon

Knock on the door… if you dare.

    Behind the Door: the Tests

    The challenge: CodePen's October series for the brand-new Jest Block in the CodePen 2.0 editor. Each Monday's template comes with tests built in: turn them green, then dress the result up. Week one was FizzBuzz, the classic that's struck fear in many a new JavaScript developer, now in a Halloween cape. Threes say Boo, fives say Scary, fifteens say BooScary, and everyone else just says their number.

    3 Boo 5 Scary 3 + 5 BooScary

    Here, every knock is the next number. One tiny function, ScaryFizzBuzz, decides what the house shouts back, and it's the very same one Jest checks. The house can't fib.

    The tests: The Jest Block runs them right inside the Pen. CodePen's starter arrived with every one of them failing, still the scariest thing in this house. Now all five pass on every save: threes, fives, fifteens, plain numbers, and a firm no to zero, negatives and half a knock. (Nobody knocks two and a half times. We checked.)

    The house has tests too: a second suite checks drawNight, which plans each night at the house. It uses ScaryFizzBuzz to look ahead at the next 20 scare knocks, then promises every scare plays once a night, the vampire still answers knock 3, and scares you've never met come first. Like ScaryFizzBuzz, the page imports the very function the tests check.

    The Night Is Over

    The Guest Book