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.
Intro to events module
Composition of listeners
Report a typo
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);
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.