0
0
Typescriptprogramming~10 mins

Number type behavior in Typescript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a number variable with value 10.

Typescript
let num: number = [1];
Drag options to blanks, or click blank then click option'
A10
Btrue
C'10'
D"10"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, which makes it a string.
Assigning a boolean value instead of a number.
2fill in blank
medium

Complete the code to check if a number variable is NaN (Not a Number).

Typescript
if (isNaN([1])) {
  console.log("Not a number");
}
Drag options to blanks, or click blank then click option'
A"num"
BNaN
Cnum
DNumber
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the variable name as a string.
Passing the NaN constant instead of the variable.
3fill in blank
hard

Fix the error in the code to correctly convert a string to a number.

Typescript
let value: number = Number([1]);
Drag options to blanks, or click blank then click option'
Aundefined
B"123"
Ctrue
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Passing boolean or null values which convert to 0 or NaN.
Passing undefined which results in NaN.
4fill in blank
hard

Fill both blanks to create a number array and get its length.

Typescript
let numbers: number[] = [[1]];
let length: number = numbers[2];
Drag options to blanks, or click blank then click option'
A1, 2, 3
Blength
C.length
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'length' without the dot.
Using 'size' which is not a property of arrays.
5fill in blank
hard

Fill all three blanks to create a map of numbers and filter keys with values greater than 10.

Typescript
const data: Record<string, number> = {a: 5, b: 15, c: 20};
const filtered = Object.fromEntries(
  Object.entries(data).filter(([[1], [2]]) => [3] > 10)
);
Drag options to blanks, or click blank then click option'
Akey
Bvalue
Cval
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names in destructuring.
Comparing the key instead of the value.