Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a variable with a string type.
Typescript
let name: [1] = "Alice";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or boolean instead of string.
✗ Incorrect
The string type tells TypeScript that the variable name should hold text.
2fill in blank
mediumComplete the code to define a function that returns a number.
Typescript
function getAge(): [1] { return 30; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string or void as return type.
✗ Incorrect
The function returns a number, so the return type should be number.
3fill in blank
hardFix the error in the code by completing the type for the parameter.
Typescript
function greet(person: [1]) { console.log("Hello, " + person); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or boolean causes errors.
✗ Incorrect
The parameter person is used as text, so it should be a string.
4fill in blank
hardFill both blanks to create a type that can be either a string or a number.
Typescript
let value: [1] = 42; value = [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using only string or number alone.
✗ Incorrect
The type string | number means value can be a string or a number. Assigning "hello" is valid.
5fill in blank
hardFill all three blanks to create a function type that takes a number and returns a boolean.
Typescript
type Check = ([1]: [2]) => [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter or return types.
✗ Incorrect
The function type Check takes a parameter named num of type number and returns a boolean.