JavaScript 01 · Send your first Sky Island radio message

JavaScript lesson 1 of 50 · Beginner · About 15 minutes

Send Pip’s first radio messages from Central Hub and watch each instruction run in order.

A distress signal lights up Pip’s antenna at Sky Dock while two cloud creatures wait on a distant platform.
Mission Run a JavaScript program and tell which message comes from which instruction.

Get ready

Open Complete checkpoint below. Paste the JavaScript into a blank JavaScript editor and run it.

Write an instruction. Put one radio message in quotes. → Run the program. JavaScript reads the instructions in order. → Read the console. Three lines tell you what Pip says.
Write an instruction → Run the program → Read the console

Understand the JavaScript in this lesson

Language to look for JavaScript, console, console.log(), strings, comments, statements.

1. Read the first instruction

A program is a set of instructions. Start by copying the first two lines and running them. The line beginning // is a comment. It gives a human a clue about the code and JavaScript skips it. The second line is a statement, a single instruction to do something.

// Sky Island Rescue: Pip checks in from Central Hub.
console.log("Pip is at Central Hub.");

2. Send a message to the console

In console.log(...), the dot means “use something from”. JavaScript finds the log tool on console. Parentheses call that tool and hold what you want it to show. Text between matching quotes is a string. The quote marks help JavaScript find the edges of the text. You see the words inside them in the console output.

console.log("A cloud creature needs help.");

3. Put Pip’s instructions in order

Add the second message below the first, then place this third message underneath it. JavaScript reads these instructions from top to bottom, so Pip speaks in the order you wrote. Each semicolon marks the end of a statement. Run the whole file and compare the three output lines with the three console.log() calls. Change one message and run again. This is how you check that an edit did the job you expected.

console.log("Our first stop is the Workshop.");
Follow what happens step by step
  1. Run the file
    The line starting with // makes no output.Why It is a comment, so JavaScript skips it.
  2. Read the first call
    Pip is at Central Hub.Why JavaScript passes the text in quotes to console.log().
  3. Read the following calls
    A cloud creature needs help. Then the Workshop message appears.Why This program runs statements from top to bottom.

Predict before you run What changes if you swap the second and third calls?

Reveal the answer

The last two messages swap positions in the output. Their words stay the same.

Complete checkpoint

JavaScript · the instructions

// Sky Island Rescue: Pip checks in from Central Hub.
console.log("Pip is at Central Hub.");

console.log("A cloud creature needs help.");

console.log("Our first stop is the Workshop.");

Read the JavaScript line by line

Open a small group of lines while you read the complete checkpoint. Blank lines separate ideas. Closing braces mark the end of a block. An ellipsis here means you can read the rest in the full program.

Lines 2–6
Line 2 console.log("Pip is at Central Hub.");
Show a message or value in the output. Use it to watch the game work.
Line 4 console.log("A cloud creature needs help.");
Show a message or value in the output. Use it to watch the game work.
Line 6 console.log("Our first stop is the Workshop.");
Show a message or value in the output. Use it to watch the game work.

Mission challenge

Add a fourth call that tells Pip where the Beacon is. Run it and check that the new line appears last.

Change one piece at a time. Run the checkpoint again and compare what you expected with what actually happened.