title: How to create a new EventEmitter and register "open" and "close" event listeners?
body: <p>The createEmitter function should create a new EventEmitter and register &quot;open&quot; and &quot;close&quot; event listeners. The callbacks for those events should be onOpen and onClose arguments, respectively. The opened and closed methods should raise the &quot;open&quot; and &quot;close&quot; events on the EventEmitter they will receive as emitter arguments. The callbacks should only be invoked once per emitter.</p>
  <p>For example, after executing the following code, it should print &quot;Opened!&quot; and then &quot;Closed!&quot;:</p>
  <pre><code>let emitter = createEmitter(
    () =&gt; console.log(&quot;Opened!&quot;), () =&gt; console.log(&quot;Closed!&quot;)
  );
  opened(emitter);
  closed(emitter);
  </code></pre>
  <p>My Code:</p>
  <pre><code>const events = require(&quot;events&quot;);
  const myEmitter = new events.EventEmitter();
  
  function createEmitter(onOpen, onClose) {    
  myEmitter.on('open', onOpen); 
  myEmitter.on('close', onClose);
  }
  
  function opened(emitter) {
  myEmitter.emit('open', emitter); 
  
  }
  function closed(emitter) {
  myEmitter.emit('close', emitter);
  }
  
  let emitter = createEmitter(
    () =&gt; console.log(&quot;Opened!&quot;), () =&gt; console.log(&quot;Closed!&quot;)
  );
  opened(emitter);
  closed(emitter);
  
  module.exports.createEmitter = createEmitter;
  module.exports.opened = opened;
  module.exports.closed = closed;
  </code></pre>
  <p>Output:</p>
  <pre><code>Opened!
  Closed!
  </code></pre>
  <p>Test Cases:</p>
  <pre><code>  OK: Example case: Correct answer 
    WRONG: createEmitter registers the correct events: Exception 
    OK: open and close functions raise the correct events: Correct answer 
    WRONG: Callbacks are only invoked once: Wrong answer
  </code></pre>
  <p>Could Anyone explain why the Wrong Answer and the Exception?</p>