0
0
Typescriptprogramming~10 mins

Why understanding the boundary matters in Typescript - Test Your Understanding

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

Complete the code to print numbers from 0 to 4.

Typescript
for(let i = 0; i [1] 5; i++) {
  console.log(i);
}
Drag options to blanks, or click blank then click option'
A<=
B<
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= 5 causes the loop to run one extra time.
2fill in blank
medium

Complete the code to check if a number is within the boundary 1 to 10 (inclusive).

Typescript
if(num [1] 1 && num [2] 10) {
  console.log('Inside boundary');
}
Drag options to blanks, or click blank then click option'
A>=
B<=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using > 1 excludes 1 from the boundary.
3fill in blank
hard

Fix the error in the loop boundary to avoid an infinite loop.

Typescript
let count = 0;
while(count [1] 5) {
  console.log(count);
  count--;
}
Drag options to blanks, or click blank then click option'
A<
B<=
C>=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using < causes the loop to never end because count decreases.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Typescript
const words = ['apple', 'bat', 'carrot', 'dog'];
const lengths = Object.fromEntries(words.filter(w => w.length > 3).map(word => [[1], [2]]));
Drag options to blanks, or click blank then click option'
Aword
Bword.length
Cwords.filter(w => w.length > 3)
Dword => word.length
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole array as a key or value.
5fill in blank
hard

Fill all three blanks to create an object with uppercase keys and values greater than 0.

Typescript
const data = { a: 1, b: 0, c: 3 };
const result = Object.fromEntries(Object.entries(data).filter(([k,v]) => v > 0).map(([[3],v]) => [[1], [2]]));
Drag options to blanks, or click blank then click option'
Ak.toUpperCase()
Bv
Ck
DObject.entries
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys without uppercase.