From visual blocks to typed JavaScript

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

This From visual blocks to typed JavaScript worksheet is part of the ACARA Digital Technologies Years 7–8 — Programming with Control Structures and Functions (JavaScript) journey. Print it as a booklet?

From visual blocks to typed JavaScript

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. In typed JavaScript, a block like "say Hello" becomes what?
A A coloured shape you drag onto the screen
B One line of text you type: console.log("Hello");
2. Which spelling will a computer accept?
A console.log("Hi");
B Console.Log("Hi");
3. You type consle.log("Hi"); by mistake. What happens?
A The computer guesses what you meant and prints Hi
B The computer does not understand it and shows an error
4. Which statement is true about JavaScript?
A It is a text-based language that professional programmers use
B It is only a toy language made for practising with blocks
5. A block program uses sequence, decisions and repeats. What changes when you move to JavaScript?
A The same ideas are used, but you type them as text
B The ideas are different, so you must learn new ones

Match the Pairs

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

Left columnRight column
1console.log("Hi"); Aconsole.log("Start"); console.log("End");
2let score = 0; BOne typed line that does the job of a 'set score to 0' variable block
3Sequence still applies in typed code: lines run from top to bottom, just like stacked blocks Cif (score > 10) { console.log("Win"); }
4A decision from an if block becomes typed text using the word if, a condition and curly braces DWrong capital letter: JavaScript is case sensitive, so Console is not the same as console. It must be console.log.
5Console.log("Hello"); EThe closing quote is missing, so the text is not closed. It needs a matching quote before the bracket.
6console.log("Hello); FOne typed line that does the same job as a 'say Hi' block, and it must be spelled exactly

Definitions

JavaScript

Fill in the Blanks

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

1.
___________("Hello, world!");
2.
let name = ______("What is your name?");
3.
__ (score > 5) { console.log("You win!"); }
4.
___ (let i = 0; i < 3; i++) { console.log("Hi"); }
5.
___ lives = 3; lives = lives - 1; console.log(lives);

Spot the Error

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

Question 1
A let name = promt("Name?");
B console.log("Hi " + name);
C console.log("Welcome!");
Question 2
A let score = 8;
B score = score + 2;
C console.log(scor);
Question 3
A let age = 13;
B if (age >= 13) {
C Console.log("Teen");
D }
Question 4
A let total = 0;
B for (let i = 1, i <= 3, i++) {
C total += i;
D }
Question 5
A let n = 3;
B while n > 0 {
C console.log(n);
D n--;
E }

Answer Key

From visual blocks to typed JavaScript
Section A: Quick Questions
Q1
B — One line of text you type: console.log("Hello");
Q2
A — console.log("Hi");
Q3
B — The computer does not understand it and shows an error
Q4
A — It is a text-based language that professional programmers use
Q5
A — The same ideas are used, but you type them as text
Section B: Match the Pairs
Q1
console.log("Hi"); → One typed line that does the same job as a 'say Hi' block, and it must be spelled exactly
Q2
let score = 0; → One typed line that does the job of a 'set score to 0' variable block
Q3
Sequence still applies in typed code: lines run from top to bottom, just like stacked blocks → console.log("Start"); console.log("End");
Q4
A decision from an if block becomes typed text using the word if, a condition and curly braces → if (score > 10) { console.log("Win"); }
Q5
Console.log("Hello"); → Wrong capital letter: JavaScript is case sensitive, so Console is not the same as console. It must be console.log.
Q6
console.log("Hello); → The closing quote is missing, so the text is not closed. It needs a matching quote before the bracket.
Section C: Definitions
Q1
JavaScript — A text-based language where each block you snapped together becomes one line of code that you type exactly, and the computer follows it literally.
Section D: Fill in the Blanks
Q1
console.log("Hello, world!");
Q2
let name = prompt("What is your name?");
Q3
if (score > 5) { console.log("You win!"); }
Q4
for (let i = 0; i < 3; i++) { console.log("Hi"); }
Q5
let lives = 3; lives = lives - 1; console.log(lives);
Section E: Spot the Error
Q1
A — prompt is spelled wrong. Typed code must be exact, so the computer cannot find promt. It should be prompt("Name?").
Q2
C — The variable name is misspelled. The computer follows the text literally and has no variable called scor. It should be console.log(score);
Q3
C — JavaScript cares about capital letters. Console with a capital C does not exist. It should be console.log("Teen");
Q4
B — The three parts of a for loop are separated by semicolons, not commas. It should be for (let i = 1; i <= 3; i++) {
Q5
B — The repeat condition of a while loop must be inside round brackets. It should be while (n > 0) {