Type Conversion

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

Type Conversion

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does Number() convert a value into a number?
A No
B Yes
2. Does String() convert a value into a string?
A Yes
B No
3. Is 'number' with a lowercase n a valid conversion function?
A No
B Yes
4. Does Boolean() convert a value into true or false?
A No
B Yes
5. Do type conversion functions need parentheses around the value?
A Yes
B No

Match the Pairs

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

Left columnRight column
1Number("5") AConverts the number 12 into the string "12"
2String(12) BConverts the string "5" into the number 5
3Converts a value into true or false CWrong - String() needs parentheses around the value
4Turns text into a number data type DBoolean(1)
5let n = number("5"); EWrong - 'Number' must start with a capital N
6let text = String age; FNumber(input)

Definitions

Number()

Fill in the Blanks

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

1.
let ageText = ______(age);
2.
let num = ______(input);
3.
let flag = _______(1);
4.
let count = ______("8");
5.
let label = ______(score);

Spot the Error

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

Question 1
A let num = "5";
B let x = number(num);
C console.log(x);
Question 2
A let age = 12;
B console.log(text);
C let text = string(age);
Question 3
A let b = boolean(val);
B let val = 1;
C console.log(b);
Question 4
A let s = "9";
B let n = Number(s);
C let m = Numbr(s);
Question 5
A let age = 20;
B let txt2 = Sting(age);
C let txt = String(age);

Answer Key

Type Conversion
Section A: Quick Questions
Q1
B — Yes
Q2
A — Yes
Q3
A — No
Q4
B — Yes
Q5
A — Yes
Section B: Match the Pairs
Q1
Number("5") → Converts the string "5" into the number 5
Q2
String(12) → Converts the number 12 into the string "12"
Q3
Converts a value into true or false → Boolean(1)
Q4
Turns text into a number data type → Number(input)
Q5
let n = number("5"); → Wrong - 'Number' must start with a capital N
Q6
let text = String age; → Wrong - String() needs parentheses around the value
Section C: Definitions
Q1
Number() — Converts a value, like a string, into a number data type.
Section D: Fill in the Blanks
Q1
let ageText = String(age);
Q2
let num = Number(input);
Q3
let flag = Boolean(1);
Q4
let count = Number("8");
Q5
let label = String(score);
Section E: Spot the Error
Q1
B — 'Number' must start with a capital N, not lowercase.
Q2
C — 'String' must start with a capital S, not lowercase.
Q3
A — 'Boolean' must start with a capital B, not lowercase.
Q4
C — 'Number' is misspelled as 'Numbr'.
Q5
B — 'String' is misspelled as 'Sting'.