On lesson 4 under Modules (module.exports II), the error when using arrow syntax that others have noted here confused me at first as well and I think it is something that is not appropriately addressed in the lesson. The reason is that when change from function() syntax to arrow syntax, the meaning of the this keyword changes. In function syntax, this refers to the parent object which is being assigned to module.exports so this.myAirplane works correctly. In an arrow function, this refers to the owner of the function, which is undefined so in that scope, this.myAirplane is no longer defined. If you change this.myAirplane to a string literal in the arrow function, you will see that it now works fine. You can also concatenate “this” to your string literal to see the value of this for each of the two types of function declaration.
I had difficulty with step 3.
I had written “function ()”
I (out of habit) had added a space between function and ().
This was rejected and it took a while to figure out that I could only pass on to the next step if I removed the space and wrote “function()”.
The code will work fine with the additional space but step 3 required that it wasn’t there.
My code isn’t working for step 4, so I copied and pasted the hints code.
It didn’t work.
If anyone knows how to make this work, just reply below. Thanks!
I’m sorry, it worked, I was supposed to put it in the file 2-mission-control.js. Sorry about that!
The test is broken on this unit. It is strictly checking unnecessary whitespaces as well as double quotes which can be quite frustrating.
I failed by using double quotes later in step 4. I found it really confusing and frustrating as I’d been lead to believe that you can just pick single or double quotes in other situations.
Hi!
in the 5th question of the topic module.exports II, I wrote my code like this:
const Airplane = require(’./2-airplane.js’);
function displayAirplane() {
console.log(Airplane.displayAirplane());
}
But gives me this error:
Log Airplane.displayAirplane()
to display CloudJet
in the console.
what’s wrong with my code?
Tks
In instruction 5 it asks you to log the result of calling displayAirplane()
on the Airplane
object.
You created another function called displayAirplane
that does that, it is unnecessary.
just the require and console.log is enough.