Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the module correctly.
Node.js
const fs = require([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the module name.
Using incorrect module names.
✗ Incorrect
In Node.js, to use a built-in module like fs, you must require it by its name as a string.
2fill in blank
mediumComplete the code to export a function from a module.
Node.js
module.exports = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting a function call instead of the function.
Exporting the function name as a string.
✗ Incorrect
To export a function, assign the function itself (not a call or string) to module.exports.
3fill in blank
hardFix the error in importing a custom module.
Node.js
const utils = require([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the relative path prefix.
Including the file extension when not needed.
✗ Incorrect
When importing a local module, you must use a relative path starting with ./ or ../.
4fill in blank
hardFill both blanks to create a module that exports an object with two functions.
Node.js
module.exports = { [1]: function() {}, [2]: () => {} }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid identifiers as keys.
Forgetting commas between object properties.
✗ Incorrect
We export an object with keys naming the functions. Here, start and stop are function names.
5fill in blank
hardFill all three blanks to import a module, call a function, and log the result.
Node.js
const [1] = require('[2]'); const result = [3].calculate(); console.log(result);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using file extension in require path.
Mismatching variable and module names.
✗ Incorrect
We import the module as mathUtils from 'math-utils', then call mathUtils.calculate().