FAQ: Intermediate JavaScript Modules - Named Exports

This community-built FAQ covers the “Named Exports” exercise from the lesson “Intermediate JavaScript Modules”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Named Exports

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hey guys and girls!

My first question here:
How come the function below can acces ‘availableStaff’ as a parameter? (Since ‘availableStaff’ is defined in availableAirplanes, I would expect to acces it as availableAirplanes.availableStaff)

—function meetsStaffRequirements(availableStaff, requiredStaff)— ((question number 7))

I am probably missing something really obvious, but I can’t figure out what it is. Thanks in advance!

Not sure I can explain this properly, but I’ll give it a go. In the exercise, when you call your meetsStaffRequirements(availableStaff, requiredStaff) function, you are doing so from within a forEach iteration of the availableAirplanes array. You are sending the availableStaff property from each “airplane” object in the array as a parameter along with the requiredStaff property of the flightRequirements object. Hopefully this helps a little. :grinning:

2 Likes

thanks, that helps! :slight_smile:

Very poorly designed lesson. There is no need to explicitly state that named exports need to have empty objects or functions.

This is a better explanation of this topic:

3 Likes

Hello there!

I’m not too sure about what’s wrong with my code. Every step of the exercise got a checkmark - except the last one where I have to do the named export. Looking at the hint I can confirm my code is the same as the tutorial’s. Skipping right to the solution, though I wonder what happened there… Here is my code:

let flightRequirements  = {
  requiredStaff: 4,
};

let availableAirplanes = [
{
  name: 'AeroJet',
  fuelCapacity: 800,
  availableStaff: ['pilots', 'flightAttendants', 'engineers', 'medicalAssistance', 'sensorOperators']
 }, 
 {
   name: 'SkyJet',
   fuelCapacity: 500,
   availableStaff: ['pilots', 'flightAttendants']
 }];

function meetsStaffRequirements(availableStaff, requiredStaff){
	return (availableStaff.length >= requiredStaff) ? true : false;
}

export {
  availableAirplanes,
  flightRequirements,
  meetsStaffRequirements
};

Edit: Code from the hint box of tutorial is down below and doesn’t seem to be different from what I wrote:D

export { availableAirplanes, flightRequirements, meetsStaffRequirements};

I Modules, lesson 7 why do you use [{}}] when creating an variable object and not just {}. I thought was just for arrays And {} are sufficient for objects and variables that contain multiple properties.

This confused me at first too.

The answer is that availableAirplanes actually is an array [], not just an object.

As you know, arrays can contain different types of data:

strings = [‘happy’, ‘sad’, ‘hungry’, ‘angry’, ‘hangry’]
numbers = [589, 607, 200, 665]
mixed = [‘happy’, 200, true ]

or in this case…

objects = [{object}, {object}, {object}]

availableAirplanes is an array containing multiple objects of key: value pairs, which need to be wrapped in braces {} as shown in the lesson…

[{name: ‘AeroJet’, fuelCapacity: 800}, {name: ‘SkyJet’, fuelCapacity: 500}]

2 Likes

I accidentally messed up on step 7, I fixed the problem, but the error message is contradictive to the instructions, perhaps the wording could be changed from equals to less than? or even more sense, true instead of false… image

2 Likes

I ponder a minor detail in the explanation of named exports. Why does the text (step 2) refer to the variable specialty (initialized as an empty string) as a string object? I thought a string was a primitive datatype, not an object.

Hello, @byte5091529437.

You can read about strings here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

If you scroll down a ways you’ll see this heading: Distinction between string primitives and String objects

Hey, same thing happened to me. I’m not sure if it is just different formatting from what codecademy expected. Even though the code for export{…} appears the same try to delete what you wrote for export{…} and just copy and paste the hint. It should work then.

When I submitted mine I did not have a space between the opening { and availableAirplanes and was not granted the check mark. After removing the space I was presented with the coveted check mark. Again not sure if this is just a bug in the testing or if it has to be like that.

export { availableAirplanes, flightRequirements, meetsStaffRequirements};

Blockquote

Why is this:

const meetsStaffRequirements = (availableStaff, requiredStaff) => {
  availableStaff.length >= requiredStaff ? true : false; 
};

not acceptable code for step 7? Thanks :slight_smile:

What i have understand is that when you will call this function you will pass them argument in such a way that availableStaff is made accessiable e.g meetsStaffRequirements(availableAirplanes[0].availableStaff,flightRequirements.requiredStaff);
or you can use foreach() for passing all object element.

This Module is the the only one in Code Academy that is soo sensitive to semi colons and spacing. Found it very frustrating!

3 Likes

Some of the instruction steps in all the lessons are so vague in what they want you to do and half the time the hints seem to be wrong e.g. leaving out commas and semicolons and then adding them back on other hints. It is very frustrating!

Hi

Topic: Named Exports
Sorry guys if someone can remind/guide me what is happening here? In the following function how availableStaff and requiredStaff properties are available. It is confusing me

function meetsStaffRequirements(availableStaff, requiredStaff){
  if(availableStaff.length >= requiredStaff){
    return true;
  } else{
  return false;
}
};

Following is the Whole Module you can see this function is accessing those above mentioned properties?

const Airplane = '';
let availableAirplanes = [{
  name: 'AeroJet',
  fuelCapacity: 800,
  availableStaff: ['pilots', 'flightAttendants', 'engineers', 'medicalAssistance', 'sensorOperators']
},
  {name: 'SkyJet',
  fuelCapacity: 800,
  availableStaff: ['pilots', 'flightAttendants']
  }
];
let flightRequirements = {
  requiredStaff: 4,
};
function meetsStaffRequirements(availableStaff, requiredStaff){
  if(availableStaff.length >= requiredStaff){
    return true;
  } else{
  return false;
}
};
export {availableAirplanes, flightRequirements, meetsStaffRequirements};

Thanks

I know it’s a very late reply, but in Javascript wouldn’t you need return at the start of the line? Also, the conditional will evaluate to true or false, so you can just return it directly:

return availableStaff.length >= requiredStaff;

This section is so tedious and long please change it; 90% of the exercises have nothing to do with named exports

Not sure I understood your explanation. Where do we get that forEach method?bc its not in the code explicitly.And I checked the functionality of the code in the lesson by calling the function meetsStaffRequirements and it doesnt work(error in the screenshot)

. after I added the indexation it worked obviously

function meetsStaffRequirements(availableStaff,requiredStaff){
if (availableAirplanes[0].availableStaff.length>=flightRequirements.requiredStaff){
return true
} else {
return false
}