forked from lizbur10/js-object-oriented-classes-travel-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (59 loc) · 1.53 KB
/
index.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Driver{
constructor(name,day){
this.name=name
this.day=day
}
static startDate(){
const st = new Date('1980');
return st.getFullYear();
}
yearsExperienceFromBeginningOf(){
let d=new Date();
console.log(Driver.startDate())
return d.getFullYear()- Driver.startDate() ;
}
}
let s=new Driver()
s.yearsExperienceFromBeginningOf()
let eastWest = [
'1st Avenue',
'2nd Avenue',
'3rd Avenue',
'Lexington Avenue',
'Park',
'Madison Avenue',
'5th Avenue'
];
class Route{
constructor(beginningLocation ,endingLocation){
this.beginningLocation=beginningLocation;
this.endingLocation=endingLocation;
}
blocksTravelled(eastWest){
return Math.abs(this.beginningLocation.vertical-this.endingLocation.vertical)+Math.abs(eastWest.indexOf(this.beginningLocation.horizontal)-eastWest.indexOf(this.endingLocation.horizontal))
}
estimatedTime(eastWest,peak){
if(peak){
return Math.ceil(this.blocksTravelled(eastWest)/3);
}
else{
return Math.ceil(this.blocksTravelled(eastWest)/2);
}
}
}
// let route = new Route(
// { horizontal: 'Park', vertical: '34' },
// { horizontal: 'Park', vertical: '45' }
// );
// let route = new Route(
// { horizontal: '1st Avenue', vertical: '34' },
// { horizontal: 'Park', vertical: '30' }
// );
let route = new Route(
{ horizontal: '1st Avenue', vertical: '34' },
{ horizontal: 'Park', vertical: '45' }
);
console.log(route);
route.blocksTravelled(eastWest)
let peak=false;
route.estimatedTime(eastWest,peak)