Computer scienceBackendNode.jsCore ConceptsInternal modulesEventsEvents module basics

Intro to events module

The sum

Report a typo

You are given a program that already has a listener for the sum event. You should use the emit method to trigger an event so that the string with the sum of the numbers 1 and 4 is displayed on the console.

Write a program in JavaScript
const EventEmitter = require('events'); //do not change this line!

const emitter = new EventEmitter();

emitter.on('sum', (firstNum, secondNum) => {
console.log(`The sum is ${firstNum + secondNum}`);
});

emitter.emit(/* your code */);
___

Create a free account to access the full topic