Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a variable inside a module scope.
Javascript
const [1] = 10; console.log(value);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than the one logged.
Using var which is function scoped, not module scoped.
✗ Incorrect
The variable value is declared with const inside the module, so it is scoped to this module only.
2fill in blank
mediumComplete the code to export a function from a module.
Javascript
export default function [1]() { return 'Hello from module'; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that is not descriptive.
Forgetting to export the function.
✗ Incorrect
The function greet is exported so it can be used outside this module.
3fill in blank
hardFix the error in the code by completing the import statement correctly.
Javascript
import [1] from './module.js'; console.log(greet());
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name than the exported function.
Forgetting to import the function.
✗ Incorrect
The import must match the exported function name greet from the module.
4fill in blank
hardFill both blanks to create a private variable and a public function accessing it.
Javascript
const [1] = 42; export function getValue() { return [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in the two blanks.
Trying to export the variable directly.
✗ Incorrect
The variable secretNumber is private to the module, and the exported function getValue returns its value.
5fill in blank
hardFill all three blanks to export a constant, import it, and log its value.
Javascript
export const [1] = 3.14; import { [2] } from './constants.js'; console.log([3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for export and import.
Logging a variable that was not imported.
✗ Incorrect
The constant PI is exported, imported, and logged correctly.