INTERMEDIATE JAVASCRIPT MODULES : Import


#1

Hi Guys,

I’m working on this exercise and I’m on the last step: 6.

As everyone knows, these tutorials break up the lesson into 3 panels in your web browser.

  • Tutorial (left side)
  • Enter code (middle)
  • Console (right side)

I noticed that the Enter code (middle) panel only lists the file missonControl.js. This is confusing for me because the answer to Step 1 is “import Airplane from ‘./airplane’;”. Shouldn’t i see a airport.js tab in the middle panel?

I’m getting an error with my code and need help trying to understand if it is my code or the codecademy lesson. Here is the code that I put into the middle panel:

import Airplane from './airplane';
function displayFuelCapacity () {
  Airplane.availableAirplanes.forEach(function(element){
    console.log('Fuel Capacity of ' + Airplane.availableAirplanes.name + ': ' + Airplane.availableAirplanes.fuelCapacity);
  });
};

displayFuelCapacity();

Here are the results that I see in the right panel:

Fuel Capacity of undefined: undefined
Fuel Capacity of undefined: undefined

Any suggestions on what I’m doing wrong? thanks…


#2
'Fuel Capacity of ' + Airplane.availableAirplanes.name + ': ' + Airplane.availableAirplanes.fuelCapacity)

The forEach method is iterating over the array object with the temporary variable, element.

`Fuel Capacity of ${element.name}: ${element.fuelCapacity}`

#3

Perhaps the issue i’m having is that i can’t define what ‘element.name’ is supposed to be. Here’s what i’ve tried that doesn’t work:

  • Airplane.availableAirplanes.name
  • availableAirplanes.name
  • this.availableAirplanes.name
  • this.Airplane.availableAirplanes.name
  • Airplane.this.availableAirplanes.name

The error in the 3rd panel (console) is:

/home/ccuser/workspace/intermediate-javascript_modules-airplanes/airplane.js:3
Airplane.availableAirplanes = [{
^

ReferenceError: Airplane is not defined

it is almost as if my script isn’t finding airplane.js. Perhaps the first line has an error?

import Airplane from './airplane';

#4
  Airplane.availableAirplanes.forEach(function(element){
    console.log('Fuel Capacity of ' + Airplane.availableAirplanes.name + ': ' + Airplane.availableAirplanes.fuelCapacity);
  });
Array.forEach(function(element){
    console.log(`Fuel Capacity of ${element.name}: ${element.fuelCapacity}`);
});

#5

Apparently, I just don’t get it. it isn’t working for me. Is it possible to go somewhere and just get the answer?

BTW: The code I saved in this exercise over wrote the code I had already written in this exercise… crazy. I tested it a few times. Perhaps my browser is playing tricks on me.


#6

Array in my example is supposed to be,

Airplane.availableAirplanes.forEach

#7

Thank you. I’ll try this later as i’m working on another exercise and my browser is struggling with a caching issue when i jump between exercises.