Use an IIFE to Create a Module's help

I have that but how can I get it be printed or invoked? I mean the last tree lines of code

Your code so far


let funModule = (function() {
  return {
    isCuteMixin: function(obj) {
      obj.isCute = function() {
        return true;
      }
    },
    singMixin: function(obj) {
      obj.sing = function() {
        console.log("Singing to an awesome tune");
      };
    }
  }
})();

let bird;
funModule.singMixin(bird);
bird.sing()

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module

Hi!

You must call the bird’s methods, not the module’s. When you do this:

funModule.singMixin(bird)

You’re actually adding functions/methods to the bird object, hence You call it like this:

let bird = {} // If left empty (like "let bird;") will yield an undefined object.
funModule.singMixin(bird) // Add the method **sing** to the bird.
funModule.isCuteMixin(bird) // Adds the method **isCute** to the bird.

console.log(bird.isCute()) // output: true
bird.sing() // output: Singing to an awesome tune

Hope it helps :slight_smile:.

Regards!

2 Likes

He beat me to the punch. Your line:

let bird;

isn’t doing what you think it’s doing. You’re declaring the variable bird, but you haven’t set it to any type. It doesn’t know if you’ll use it for a Boolean, a String, an Array or an Object. In your case, you really want to initialize it as an empty object, so you can add properties to that object, by a mixin.

You were REALLY close, just missing three characters. The ones to assign an empty object. :wink:

2 Likes

Really thanks for clear explanation from both of you dears…