-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFlight.html
48 lines (47 loc) · 1.56 KB
/
Flight.html
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
<HTML>
<HEAD>
<TITLE>Instance method demo</TITLE>
</HEAD>
<BODY>
<SCRIPT>
function Aircraft(fName,maximum) {
// set properties here.
this.fName = name; // Properties
this.maximum = maximum;
}
function Flight(flightNum,reserv,fName,maximum) {
// set properties here.
this.flightNum = flightNum; // Properties
this.fName = fName;
this.flight = new Aircraft(fName,maximum);
this.reserv = reserv;
this.seats = this.flight.maximum-this.reserv;
}
Flight.prototype.bookSeats = function(noSeats){
if(this.seats>noSeats){
this.seats-=noSeats
}
else throw "Not enough Seats to reserve on\nFlight Number: "+
this.flightNum;
}
var firstFlight = new Flight("1234",20,"First Flight",300);
var secondFlight = new Flight("4321",30,"Scond Flight",100);
try{
firstFlight.bookSeats(100);
secondFlight.bookSeats(10);
alert("Flight Number: "+firstFlight.flightNum+
"\nFlight Name: "+firstFlight.fName+
"\nMax Seats:"+firstFlight.flight.maximum+
"\nSeats Left: "+firstFlight.seats+
"\nFlight Number: "+secondFlight.flightNum+
"\nFlight Name: "+secondFlight.fName+
"\nMax Seats:"+secondFlight.flight.maximum+
"\nSeats Left: "+secondFlight.seats);
}
catch(err){
alert(err);
}
</SCRIPT>
</H1>
</BODY>
</HTML>