-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparkingLot.js
More file actions
43 lines (41 loc) · 1.07 KB
/
parkingLot.js
File metadata and controls
43 lines (41 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class ParkingLot{
constructor(capacity){
this.capacity = capacity;
this.number = 0;
this.cars = {};
}
park(brand,model){
if (this.number < this.capacity){
this.cars[brand] = model;
this.number++;
} else {
if (this.number >= this.capacity){
console.log('The parking lot is full');
}
}
}
exit(brand,model){
if (!this.cars[brand]){
console.log('We cant seem to find your car');
}
for (let key in this.cars){
if (this.cars[key] === model){
console.log('Here is your car');
delete this.cars[key];
this.number--;
}
}
}
available(){
if (this.number < this.capacity){
console.log('There are spots in the parking Lot!')
}
}
}
var parkingLot = new ParkingLot(3);
parkingLot.park('Mercedes','E350');
parkingLot.park('Honda','Civic');
parkingLot.park('Toyota','Camry');
parkingLot.park('Lamborghini','Murcialago')
parkingLot.exit('Toyota','Camry');
console.log(parkingLot);