O'Reilly logo

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond by JD Isaacks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lesson 14. Capstone: Simulating a lock and key

In this capstone exercise you’re going to build a lock and key system. Each lock will have its own key that’s unique to it. The lock will hold some secret data and only return the data if accessed with the correct key. You’ll then build a game where you generate three locks and give the player only one key and one chance to unlock a prize!

14.1. Creating the lock and key system

You’ll start by designing the lock API. You want to have a function called lock which accepts a single parameter that’s the data you’re locking up. It should then return a unique key (key as in key to a lock) and an unlock function that reveals the secret if invoked with the correct key. So the high-level API is basically ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required