Turning pseudocode or a flowchart into JavaScript

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

Turning pseudocode or a flowchart into JavaScript

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. The pseudocode step is: SET score TO 0. Which JavaScript statement matches it?
A let score = 0;
B score == 0;
2. The pseudocode step is: ASK 'What is your name?' and store it in name. Which JavaScript matches?
A let name = console.log('What is your name?');
B let name = prompt('What is your name?');
3. In a flowchart, a diamond shape asks a yes/no question such as 'Is age >= 13?'. Which JavaScript does it become?
A if (age >= 13) { ... }
B let (age >= 13) { ... }
4. A flowchart has a parallelogram labelled 'OUTPUT total'. Which JavaScript matches?
A prompt(total);
B console.log(total);
5. A flowchart diamond 'Is count < 5?' has a Yes path that returns to the diamond after adding 1 to count. Which JavaScript shows this?
A while (count < 5) { count++; }
B if (count < 5) { count++; }

Match the Pairs

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

Left columnRight column
1let age = prompt("Enter your age"); AThe pseudocode step ASK for name is an input, so it should use prompt(), not console.log(), which only displays output.
2while (lives > 0) { Bif (score >= 10) {
3The pseudocode step SET total TO 0 becomes a variable declaration with let. CTranslates a decision diamond with an arrow looping back: while lives is more than 0, repeat the steps inside.
4A decision diamond that asks 'Is score >= 10?' becomes an if statement with the same condition. Dlet total = 0;
5if (score = 10) { ETranslates a parallelogram input step: INPUT age. The answer from the user is stored in the variable age.
6let name = console.log("Enter your name"); FThe diamond asks 'Is score equal to 10?' but the code uses = which assigns a value. It should use === to compare.

Definitions

let score = 0;

Fill in the Blanks

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

1.
// SET score TO 0 ___ score = 0;
2.
// ASK "Your name?" let name = ______("Your name?");
3.
__ (score > 10) { console.log("Well done!"); }
4.
while (lives _ 0) { lives--; }
5.
let total = 5 + 3; ___________(total);

Spot the Error

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

Question 1
A let score == 0;
B score = score + 5;
C console.log(score);
Question 2
A let name = prompt("Name?");
B let age = prompt("Age?");
C print(name, age);
Question 3
A let mark = 72;
B if mark >= 50 {
C console.log("Pass");
D }
Question 4
A let city = ask("City?");
B console.log("Hi " + city);
C console.log(city.length);
Question 5
A let count = 1;
B repeat (count <= 3) {
C console.log(count);
D count++;
E }

Answer Key

Turning pseudocode or a flowchart into JavaScript
Section A: Quick Questions
Q1
A — let score = 0;
Q2
B — let name = prompt('What is your name?');
Q3
A — if (age >= 13) { ... }
Q4
B — console.log(total);
Q5
A — while (count < 5) { count++; }
Section B: Match the Pairs
Q1
let age = prompt("Enter your age"); → Translates a parallelogram input step: INPUT age. The answer from the user is stored in the variable age.
Q2
while (lives > 0) { → Translates a decision diamond with an arrow looping back: while lives is more than 0, repeat the steps inside.
Q3
The pseudocode step SET total TO 0 becomes a variable declaration with let. → let total = 0;
Q4
A decision diamond that asks 'Is score >= 10?' becomes an if statement with the same condition. → if (score >= 10) {
Q5
if (score = 10) { → The diamond asks 'Is score equal to 10?' but the code uses = which assigns a value. It should use === to compare.
Q6
let name = console.log("Enter your name"); → The pseudocode step ASK for name is an input, so it should use prompt(), not console.log(), which only displays output.
Section C: Definitions
Q1
let score = 0; — Translates the pseudocode step SET score TO 0. Each step of pseudocode or a flowchart becomes one JavaScript statement: ask is prompt, a decision diamond is if, a loop arrow is while.
Section D: Fill in the Blanks
Q1
// SET score TO 0 let score = 0;
Q2
// ASK "Your name?" let name = prompt("Your name?");
Q3
if (score > 10) { console.log("Well done!"); }
Q4
while (lives > 0) { lives--; }
Q5
let total = 5 + 3; console.log(total);
Section E: Spot the Error
Q1
A — The pseudocode step SET score TO 0 is an assignment, so it needs a single = sign. The == symbol compares values and cannot be used to create a variable. It should be let score = 0;
Q2
C — A parallelogram or PRINT step that shows output becomes console.log() in JavaScript. There is no print() function here. It should be console.log(name, age);
Q3
B — A decision diamond becomes an if statement, and the condition must be inside round brackets. It should be if (mark >= 50) {
Q4
A — The pseudocode word ASK becomes prompt() in JavaScript. ask() is not a JavaScript function. It should be let city = prompt("City?");
Q5
B — A flowchart arrow that loops back while a condition is true becomes a while loop. repeat is not a JavaScript keyword. It should be while (count <= 3) {