Computer scienceBackendNode.jsCore ConceptsInternal modulesEventsEvents module basics

Intro to events module

Composition of listeners

Report a typo

You are given a piece of code with set listeners for various events. You need to write the logic for comparing numbers in the comparison event handler and, based on the results of the comparison, generate either the less event if the first number is less than the second, or the more event if the first number is greater than the second.

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

const emitter = new EventEmitter();

emitter.on('more', () => {
console.log('The second number is less!');
})

emitter.on('less', () => {
console.log('The first number is less!');
})

emitter.on('comparison', (firstNum, secondNum) => {
/* your code */
});

emitter.emit('comparison', 5, 11);
___

Create a free account to access the full topic