Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a type annotation for the parameter name.
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
number or boolean instead of string.Omitting the type annotation.
✗ Incorrect
The parameter
name should be a string because it represents a person's name.2fill in blank
mediumComplete the code to add a type annotation for the parameter age.
Typescript
function setAge(age: [1]) {
console.log(`Age set to ${age}`);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
string instead of number.Using
boolean or object incorrectly.✗ Incorrect
The parameter
age should be a number because it represents a numeric value.3fill in blank
hardFix the error by adding the correct type annotation for the parameter isActive.
Typescript
function setActive(isActive: [1]) { if (isActive) { console.log('Active'); } else { console.log('Inactive'); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
string or number instead of boolean.Omitting the type annotation.
✗ Incorrect
The parameter
isActive should be a boolean because it represents a true/false value.4fill in blank
hardFill both blanks to add type annotations for parameters title and pages.
Typescript
function createBook(title: [1], pages: [2]) { return `${title} has ${pages} pages.`; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the types between
title and pages.Using
boolean or object incorrectly.✗ Incorrect
The
title is a string because it is text, and pages is a number because it counts pages.5fill in blank
hardFill all three blanks to add type annotations for parameters firstName, lastName, and age.
Typescript
function personInfo(firstName: [1], lastName: [2], age: [3]) { return `${firstName} ${lastName} is ${age} years old.`; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the types for names and age.
Using
boolean for any parameter.✗ Incorrect
Both
firstName and lastName are string types because they are text, and age is a number.