Work Around Project Stuck on Step 7

Here is the exercise: https://www.codecademy.com/courses/learn-intermediate-javascript/projects/es6-modules-workaround

Everything seems to go well, however, when I try and export the workAroundModule.js into the main.js file, the browser on the right side goes back to not displaying what it should be.

I have tried looking at other people’s fixes and tried them, but to no avail sadly.

Here is my main.js import section

import {getRoles, getCompanies} from './modules/salaryData.js'
import {getIndustryAverageSalary, getSalaryAtCompany, getAverageSalaryByCompany, getAverageSalaryByRole} from './modules/workAroundModule.js'

My workAroundModule.js file:

import {getDataByRole, getDataByCompany} from 
'./salary.js'
import resources from './salary.js'
const {salaryData} = resources;
// Replace the empty array with the appropriate imported function/value
const getAverageSalaryByRole = role => {
  const roleData = getDataByRole(role);
  const salariesOfRole = roleData.map(obj => obj.salary);
  return calculateAverage(salariesOfRole);
}

// Replace the empty array with the appropriate imported function/value
const getAverageSalaryByCompany = company => {
  const companyData = getDataByCompany(company);
  const salariesAtCompany = companyData.map(obj => obj.salary);
  return calculateAverage(salariesAtCompany);
}

// Replace the empty array with the appropriate imported function/value
const getSalaryAtCompany = (role, company) => {
  const companyData = getDataByCompany(company);
  const roleAtCompany = companyData.find(obj => obj.role === role);
  return roleAtCompany.salary;
}

// Replace the empty array with the appropriate imported function/value
const getIndustryAverageSalary = () => {
  const allSalaries = salaryData.map(obj => obj.salary);
  return calculateAverage(allSalaries);
}


// Helper Function. Do not edit.
// Note: This function does not need to be exported since it is only used by the functions contained within this module.
function calculateAverage(arrayOfNumbers) {
  let total = 0;
  arrayOfNumbers.forEach(number => total += number);
  return (total / arrayOfNumbers.length).toFixed(2);
}

export {getIndustryAverageSalary, getSalaryAtCompany, getAverageSalaryByCompany, getAverageSalaryByRole};

and lastly, my salaryData.js file:

export {getRoles, getCompanies, getDataByRole, getDataByCompany};
const resources = salaryData;
export default resources;


Hi,
There looks like two issues I can see.
Firstly, the curly brackets around salaryData in workAroundModule.
Secondly, you appear to have misnamed salaryData in your workAroundModule imports

import {getDataByRole, getDataByCompany} from 
'./salary.js' // << should this be salary.js or salaryData.js ?
import resources from './salary.js' // << should this be salary.js or salaryData.js ?
const salaryData = resources; // removed the { }

Also, there’s no need to use resources as a step.
I.e. try

import salaryData from './salaryData.js';

and 

export default salaryData;

Hope that helps

1 Like

Oh my goodness, thanks for the reply! I wasn’t able to see the simple mistake of not inputting “Data” onto the import.

import {getDataByRole, getDataByCompany} from 
'./salaryData.js' // Added "Data"
import resources from './salaryData.js' // added "Data"
const salaryData = resources; // removed the { }

Was a simple look over. Thanks so much for the help!

1 Like