Running a JavaScript program and viewing the console

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Running a JavaScript program and viewing the console

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Where does the output of console.log() appear when you run your program?
A In the editor beside your code
B In the console panel
2. You type console.log("Hi"); in the editor but have not pressed Run yet. What shows in the console?
A Nothing yet, the program has not run
B Hi
3. You change "Hi" to "Hello" in your code. What should you do to see the new output?
A Press Run again
B Wait for the console to update by itself
4. A program has console.log("A"); then console.log("B"); then console.log("C"); What does the console show?
A A, then B, then C, one per line
B C, then B, then A
5. Which statement about the console is true?
A It only exists inside the Node.js program
B It can be the console panel in Cloodit, Node.js or a browser

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1console.log("Hi"); ASends the text Hi to the console panel, where it appears after you press Run
2console.log(1); console.log(2); console.log(3); Bconsole.log("Hello, Sam!");
3You write your program in the editor panel, then press Run to see the output in the console CShows 1, then 2, then 3 in the console, one line each, in the same order as the code
4After you change your code in the editor, run it again so the console shows the new output DCode belongs in the editor, not the console. The console only displays the output after you press Run.
5Change console.log("Hi"); to console.log("Hello"); in the editor, but do not press Run. The console still shows Hi. EThe program was not run again after the change. The console only updates when you press Run, so run it again to see Hello.
6Type console.log("Hi"); into the console panel and expect it to be part of your program. Fconsole.log("Score: 10");

Definitions

console

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
_______.log("Hello, world!");
2.
console.___("Program started");
3.
let score = 5; score += 1; console.log(_____);
4.
_____ player = "Mia"; console.log(player);
5.
__ Output appears in the console console.log("Hi");

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A console.log("Start");
B console.log("Middle");
C console.log("End);
Question 2
A let name = "Mia";
B console.log("Hello");
C console.log(name);
D consol.log("Done");
Question 3
A Console.log("Ready");
B console.log("Set");
C console.log("Go");
Question 4
A let score = 10;
B console.log(score;
C score = score + 5;
D console.log(score);
Question 5
A let x = 4;
B let y = 6;
C console.log(x + z);

Answer Key

Running a JavaScript program and viewing the console
Section A: Quick Questions
Q1
B — In the console panel
Q2
A — Nothing yet, the program has not run
Q3
A — Press Run again
Q4
A — A, then B, then C, one per line
Q5
B — It can be the console panel in Cloodit, Node.js or a browser
Section B: Match the Pairs
Q1
console.log("Hi"); → Sends the text Hi to the console panel, where it appears after you press Run
Q2
console.log(1); console.log(2); console.log(3); → Shows 1, then 2, then 3 in the console, one line each, in the same order as the code
Q3
You write your program in the editor panel, then press Run to see the output in the console → console.log("Score: 10");
Q4
After you change your code in the editor, run it again so the console shows the new output → console.log("Hello, Sam!");
Q5
Change console.log("Hi"); to console.log("Hello"); in the editor, but do not press Run. The console still shows Hi. → The program was not run again after the change. The console only updates when you press Run, so run it again to see Hello.
Q6
Type console.log("Hi"); into the console panel and expect it to be part of your program. → Code belongs in the editor, not the console. The console only displays the output after you press Run.
Section C: Definitions
Q1
console — The panel beside the editor where your program's output appears after you press Run. Each console.log shows in order, and you run the program again after every change.
Section D: Fill in the Blanks
Q1
console.log("Hello, world!");
Q2
console.log("Program started");
Q3
let score = 5; score += 1; console.log(score);
Q4
const player = "Mia"; console.log(player);
Q5
// Output appears in the console console.log("Hi");
Section E: Spot the Error
Q1
C — The text "End is missing its closing quote, so the program will not run and the console shows an error instead of the output. It should be console.log("End");
Q2
D — consol is misspelled, so JavaScript cannot find it and the console shows an error. It should be console.log("Done");
Q3
A — JavaScript is case sensitive. Console with a capital C is not the same as console, so nothing is printed. It should be console.log("Ready");
Q4
B — The closing bracket is missing, so the program will not run. It should be console.log(score);
Q5
C — The variable z was never created, so running the program gives a ReferenceError in the console. It should be console.log(x + y); to show 10.