Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'number' as return type when function returns nothing.
✗ Incorrect
The void type means the function does not return any value.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'number' as return type for a function that returns nothing.
✗ Incorrect
The function type () => void means it takes no arguments and returns nothing.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving return type as boolean but returning nothing or vice versa.
✗ Incorrect
The function should return void because it does not return a value.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter type or return type other than void.
✗ Incorrect
The function type Logger takes a string argument and returns nothing (void).
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing parameter types or using a return type other than void.
✗ Incorrect
The function processInput takes a number and a string as parameters and returns nothing (void).