A Set of Instructions

Every program is a set of instructions. Sometimes the instructions exist in a single file, and sometimes they are spread across multiple files and even multiple computers. Each instruction on its own is simple. Using kittenbook.js as an example, you can see three instructions (see Listing 2.1).

Listing 2.1 kittenbook.js Instructions

var userName = prompt('Hello, what\'s your name?');document.body.innerHTML = '<h1>Hello, ' + userName + '!</h1>';

From these two lines of code, we can break out three distinct instructions:

1. Ask the user for a name.

2. Tell the computer to save that name to a variable called userName.

3. Replace the contents of document.body with the string '<h1>Hello ' + userName ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.