Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a variable with the 'any' type.
Typescript
let data: [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'number' instead of 'any' when you want no type checking.
✗ Incorrect
The 'any' type allows a variable to hold any kind of value without type checking.
2fill in blank
mediumComplete the code to assign a string value to a variable typed as 'any'.
Typescript
let value: any = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string values.
✗ Incorrect
Assigning a string value requires quotes around the text.
3fill in blank
hardFix the error in the code by choosing the correct type instead of 'any'.
Typescript
function greet(name: [1]) { return 'Hello, ' + name; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'any' loses type safety and can cause bugs.
✗ Incorrect
The function expects a string for the name parameter, not 'any'.
4fill in blank
hardFill both blanks to create a typed object instead of using 'any'.
Typescript
let user: [1] = { name: 'Alice', age: [2] };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'any' loses type safety.
Assigning age as a string instead of a number.
✗ Incorrect
Use an object type with 'name' as string and 'age' as number, and assign a number value to age.
5fill in blank
hardFill all three blanks to avoid 'any' and use proper types in this function.
Typescript
function multiply(a: [1], b: [2]): [3] { return a * b; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'any' loses type safety.
Using 'string' for parameters causes errors.
✗ Incorrect
Both parameters and the return value should be numbers to multiply correctly and avoid 'any'.