Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a type annotation for the parameter name as a string.
Typescript
function greet([1]) { return `Hello, ${name}!`; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using space instead of colon between parameter and type.
Putting the type before the parameter name.
Assigning a value instead of annotating the type.
✗ Incorrect
The correct syntax to annotate a parameter type in TypeScript is
name: string.2fill in blank
mediumComplete the code to add a type annotation for the parameter age as a number.
Typescript
function setAge([1]) {
console.log(`Age is ${age}`);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using space instead of colon.
Putting the type before the parameter name.
Assigning a value instead of annotating the type.
✗ Incorrect
The correct way to annotate a number parameter is
age: number.3fill in blank
hardFix the error in the function parameter type annotation for isActive which should be a boolean.
Typescript
function setActive([1]) {
console.log(`Active status: ${isActive}`);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using space instead of colon.
Putting the type before the parameter name.
Assigning a value instead of annotating the type.
✗ Incorrect
The correct syntax for a boolean parameter is
isActive: boolean.4fill in blank
hardFill both blanks to add type annotations for parameters title as string and pages as number.
Typescript
function bookInfo([1], [2]) { return `${title} has ${pages} pages.`; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up types for parameters.
Using space instead of colon.
Putting type before parameter name.
✗ Incorrect
The correct annotations are
title: string and pages: number.5fill in blank
hardFill all three blanks to add type annotations for parameters firstName and lastName as strings, and age as number.
Typescript
function personInfo([1], [2], [3]) { return `${firstName} ${lastName} is ${age} years old.`; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong types for parameters.
Forgetting colon between parameter and type.
Putting type before parameter name.
✗ Incorrect
The correct annotations are
firstName: string, lastName: string, and age: number.