Bad Code Practices in Import Lesson


#1

The Import Lesson has us make a function called displayFuelCapacity, in which we display the fuel capacity of all the planes in our Airplanes object. I think that some of the code is bad practice.

First, the displayFuelCapacity should be a method of Airplane and not a function, seeing as it only makes sense inside that object. We couldn’t really call it on a different class that we worked with, say Animal, from before.

Second, there is no reason to not use a Template Literal instead of regular string notation. It’s less code, and it works.

Here is my code for the lesson:

import Airplane from './airplane';

Airplane.displayFuelCapacity = function(){
  this.availableAirplanes.forEach(function(element){
    console.log(`Fuel Capacity of ${element.name}:` +
                ` ${element.fuelCapacity}.`);
  })
};

Airplane.displayFuelCapacity();

Is there a reason why this isn’t okay for the lesson?

https://www.codecademy.com/courses/intermediate-javascript-modules/lessons/modules/exercises/import?action=resume_content_item&course_redirect=introduction-to-javascript