sketchyTK / Module-8-Challenge-Vehicle-Builder

0 stars 0 forks source link

Instructor Notes on CLI.ts #1

Open natescode opened 3 weeks ago

natescode commented 3 weeks ago

Cli.ts

Make sure to use the answers parameter passed to your .then method to know which vehicle was selected. IF the vehicle selected is the truck, assign it to a variable and say that the truck cannot itself be towed. IF the vehicle selected is NOT the truck, find it and assign it to a variable. Have the user selected the vehicle that will be towed. Call the .tow method on the truck i.e. truck.tow(selectedVehicle).

     .then((answers) => {
        // BUG: use `answers.vehicleToTow` to check which vehicle was selected
       // IF that vehicle is the truck then show your message
        // TODO: check if the selected vehicle is the truck
        // TODO: if it is, log that the truck cannot tow itself then perform actions on the truck to allow the user to select another action
        let truckTowing = false;
        for (let i = 0; i < this.vehicles.length; i++) {
            if (this.vehicles[i].vin === this.selectedVehicleVin  && this.vehicles[i] instanceof Truck) {
              console.log(`Truck cannot tow itself. Select a different vehicle to tow.`);
              truckTowing = true;
             return;
            } 
        } 
        // TODO: if it is not, tow the selected vehicle then perform actions on the truck to allow the user to select another action
        // BUG we need a loop FIND the truck (if it wasn't already selected).
         for (let i = 0; i < this.vehicles.length; i++) {
            if (this.vehicles[i].vin != this.selectedVehicleVin && this.vehicles[i] !instanceof Truck) {
                console.log(`The ${this.vehicles[i].make} ${this.vehicles[i].model} is ready to tow.`);
                return;
          // BUG: once we have the Truck in a variable then we can call `tow` as a method i.e. truck.Tow(selectedVehicleToBeTowed)
             tow(Truck);             
            } 
          }

        })
sketchyTK commented 3 weeks ago

Hi Nathan,

Thank you for your help.

I was able to get part of findVehicleToTow to work by using answers.vehicleToTow.

I tried let towTruck = Truck; towTruck.tow(answers.vehicleToTow).

Error message: Property 'tow' does not exist on type 'typeof Truck'.ts(2339)

sketchyTK commented 3 weeks ago

Tried

var towTruck = this.selectedVehicleVin; towTruck.tow(answers.vehicleToTow);

Error messages: 'towTruck' is possibly 'undefined' and Property 'tow' does not exist on type 'string'.

Also tried

var towTruck = answers.vehicleToTow; towTruck.tow(this.selectedVehicleVin);

TypeError: towTruck.tow is not a function.

sketchyTK commented 3 weeks ago

@natescode I figured out the issue and got tow & wheelie to work!