Skip to content

parkCar function fails to update carSpotMap, causing unparkCar to fail : Typescript #184

@ShashankAlampally

Description

@ShashankAlampally

Describe the bug
In ParkingLot.ts, the parkCar function successfully parks the vehicle in the Spot object but fails to save the mapping in this.carSpotMap.(Typescript)

To Reproduce

  1. Create a ParkingLot instance.
  2. Park a car using lot.parkCar(vehicle).
  3. Try to unpark the same car using lot.unparkCar(vehicle).

Expected behavior
The car should be unparked successfully.

Actual behavior
The system throws an Error: "Car is not Parked" because the map lookup returns undefined.

Suggested Fix
Add this line in ParkingLot.ts inside the parkCar method:
this.carSpotMap[vehicle.getNumber()] = availableSpot;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions