-2
\$\begingroup\$

I'm taking an online course in website development and we're going over JavaScript ES6, but my professors lecture and notes I've taken we're not very helpful more resourceful with the assignment I was given. Using proper ES6 methods, I was asked to create a class for Vehicles and two Subclasses for a bus that inclues the number of seats and Ambulance thatinclues a ttoggle for siren (on & off). Then to create an HTML file of those subclasses that allow me to drive them around using methods. Here what I have so far:

//properties
class Vehicle {
  constructor(color, direction, currentSpeed, topSpeed) {
      this._color = color; //string
      this._direction = direction; //integer 0-359 (representing a compass)
      this._currentSpeed = currentSpeed; //integer
      this._topSpeed = topSpeed; // integer
      this._engineStarted = true; //boolean
     }

//Methods:  
  turnOn() {
    this._engineStarted = true;
  }
    statusOn(){
      if(this._engineStarted){
        const statusOn = `${this._color}, ${this._direction}, ${this._currentSpeed}, ${this.topSpeed}`;
        return statusOn;
      } else {
        const status = "Engine has not been started! Vehicle is idle and inactive. Please activate";
        return status;
      }
    }
///////////////////////////////
  turnOff() {
    this._engineStarted = false;
    const status = "The Engine is now disengaged and vehicle is inactive."
  }
///////////////////////////////
  accelerate(){
    if(this._engineStarted = true){

    } else {
      const status = "Engine has not been started! Vehicle is idle and inactive. Please activate";
      return status;
    }
  }
///////////////////////////////
  brake(){
    if(this._engineStarted = true){

    } else {
      const status = "Engine has not been started! Vehicle is idle and inactive. Please activate";
      return status;
    }
  }
///////////////////////////////
  turnLeft(){
    if (this._engineStarted = true) {

    } else {
      const status = "Engine has not been started! Vehicle is idle and inactive. Please activate";
      return status;
    }
  }
///////////////////////////////
  turnRight(){
    if (this._engineStarted = true) {

    } else {
      const status = "Engine has not been started! Vehicle is idle and inactive. Please activate";
      return status;
    }
  }
}
<DOCTYPE html/>
<html>
  <head>
    <title>Vehicles</title>
  </head>
  <body>
    <script src="Johnson_ES6_Classes.js"></script>
    <script>
      let vehicle = new Vehicle()
      let bus = new Bus()
      let ambulance = new Abulance()

      alert(vehicle.status());
      alert(bus.status());
      alert(ambulance.status());
    </script>
  </body>
</html>

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles. \$\endgroup\$ – Toby Speight Sep 24 '19 at 8:31
  • \$\begingroup\$ Also, your code doesn't work. The function status() doesn't exist. \$\endgroup\$ – IEatBagels Sep 24 '19 at 15:38
0
\$\begingroup\$

This is okay for as a start. However you are missing the two classes Bus and Ambulance.

Few comments:

(1) You are using this._variableName pattern - although not wrong this is a bit redundant way to express yourself. Historically _variableName or m_variableName comes from C++ to indicate member variables. However, this.variableName already means that this is a member variable hence the "_" is redundant.

(2) The key to good design is consistency. Therefore it would make sense if all of your methods return status string or none but the status() method. Choose and stay consistent. Your current methods are all over the place.

(3) You are missing implementation on few of the methods like accelerate(), turnLeft() and turnRight();

Implement those changes and let's resume the code review.

\$\endgroup\$
  • 2
    \$\begingroup\$ Please do not answer off-topic questions, such as this one where the code is not yet working. \$\endgroup\$ – 200_success Sep 24 '19 at 3:46
  • \$\begingroup\$ @200_success Wade is obviously making his first steps and one should have proper expectation - if this is a code review the feedback can be given at any time. I see no harm in that. \$\endgroup\$ – Deian Sep 24 '19 at 13:37
  • 1
    \$\begingroup\$ The same can be said of thousands of other people who have posted unfinished homework assignments on this site. It hurts the community in the long run. \$\endgroup\$ – 200_success Sep 24 '19 at 15:21
  • \$\begingroup\$ @Deian - Thank you for your help and understanding. I greatly appreciate it \$\endgroup\$ – Wade Johnson Sep 24 '19 at 16:29
  • \$\begingroup\$ @200_success I might agree with codereview.meta.stackexchange.com/a/6389/9357 however this is simply uncompleted work by someone who need a push in the right direction. \$\endgroup\$ – Deian Sep 24 '19 at 19:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.