0
0
Node.jsframework~10 mins

EventEmitter class in Node.js - Interactive Code Practice

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

Complete the code to import the EventEmitter class from the 'events' module.

Node.js
const [1] = require('events');
Drag options to blanks, or click blank then click option'
AeventEmitter
BEmitter
CEventEmitter
DEvents
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or misspelled class names like 'Emitter' or 'eventEmitter'.
Trying to import the whole module without destructuring.
2fill in blank
medium

Complete the code to create a new instance of EventEmitter.

Node.js
const emitter = new [1]();
Drag options to blanks, or click blank then click option'
Aevents
BeventEmitter
CEmitter
DEventEmitter
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or incorrect class names.
Trying to call the module name instead of the class.
3fill in blank
hard

Fix the error in the code to add a listener for the 'start' event.

Node.js
emitter.[1]('start', () => {
  console.log('Started');
});
Drag options to blanks, or click blank then click option'
Aon
BaddListener
ConStart
Dlisten
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'listen' or 'onStart'.
Confusing with 'addListener' which also works but is less common.
4fill in blank
hard

Fill both blanks to emit the 'data' event with a message.

Node.js
emitter.[1]('[2]', 'Hello World');
Drag options to blanks, or click blank then click option'
Aemit
Bon
Cdata
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'on' instead of 'emit' to send events.
Using wrong event names like 'start' instead of 'data'.
5fill in blank
hard

Fill all three blanks to create an EventEmitter, add a listener for 'end', and emit the 'end' event.

Node.js
const [1] = new EventEmitter();
[1].[2]('end', () => {
  console.log('Finished');
});
[1].[3]('end');
Drag options to blanks, or click blank then click option'
Aemitter
Bon
Cemit
Dlistener
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Mixing up 'on' and 'emit' methods.
Using 'listener' which is not a method.