0
0
Typescriptprogramming~10 mins

Void type for functions in Typescript - Interactive Code Practice

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

Complete the code to declare a function that returns nothing.

Typescript
function greet(): [1] {
  console.log("Hello!");
}
Drag options to blanks, or click blank then click option'
Avoid
Bboolean
Cnumber
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'number' as return type when function returns nothing.
2fill in blank
medium

Complete the code to declare a function type that returns void.

Typescript
let logMessage: () => [1];
logMessage = () => console.log("Log");
Drag options to blanks, or click blank then click option'
Aboolean
Bstring
Cnumber
Dvoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'number' as return type for a function that returns nothing.
3fill in blank
hard

Fix the error in the function declaration to indicate it returns nothing.

Typescript
function showAlert(): [1] {
  alert("Warning!");
}
Drag options to blanks, or click blank then click option'
Astring
Bboolean
Cvoid
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving return type as boolean but returning nothing or vice versa.
4fill in blank
hard

Fill both blanks to declare a function type that takes a string and returns void.

Typescript
type Logger = (message: [1]) => [2];
Drag options to blanks, or click blank then click option'
Astring
Bvoid
Cnumber
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter type or return type other than void.
5fill in blank
hard

Fill all three blanks to create a function that takes a number and a string and returns void.

Typescript
function processInput(id: [1], name: [2]): [3] {
  console.log(`ID: ${id}, Name: ${name}`);
}
Drag options to blanks, or click blank then click option'
Astring
Bvoid
Cnumber
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing parameter types or using a return type other than void.