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 ...

Get Get Programming with JavaScript Next now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.