-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlyingFirstClass
145 lines (131 loc) · 4.85 KB
/
FlyingFirstClass
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!--Jeanine Rioux -->
<!-- CSC 14A 11/5/18-->
<!-- Flying First Class Lab 10 -->
<!doctype html>
<html lang = "en">
<head>
<meta charset= "utf-8">
<title>Flying First CLass</title>
</head>
<body>
<script>
var passengers = [ { name: "Ron Weasley", paid: false, ticket: "coach"},
{ name: "Lord Voldemort", paid: true, ticket: "firstclass"},
{ name: "Harry Potter", paid: false, ticket: "firstclass" },
{ name: "Hermione Granger", paid: true, ticket: "premium"} ];
function checkNoFlylist(passenger)
{
return (passenger.name === "Lord Voldemort");
}//end function check no fly list
function checkNotPaid(passenger)
{
return (!passenger.paid);
}//end function check not paid
function processPassengers(passengers, testFunction)
{
for (var i = 0; i < passengers.length; i++)
{
if(testFunction(passengers[i]))
{
return false;
}//end if test function
}//end for passengers
return true;
}//end function processPassengers
function createDrinkOrder(passenger)
{
var orderFunction;
if (passenger.ticket === "firstclass")
{
orderFunction = function()
{
document.write("Would you like a firewhiskey or ale?<br>");
}//end orderfunction;
}// end if firstclass
else if(passenger.ticket === "premium")
{
orderFunction = function()
{
document.write("Would you like ale, pumpkin juice or butter beer?<br>");
}//end orderfunction;
}// end else if premium
else
{
orderFunction = function()
{
document.write("Your options are pumpkin juice or butter beer.<br>");
}
}//end else firstclass
return orderFunction;
}// end function createDrinkOrder
function createDinnerOrder(passenger)
{
var orderFunction;
if(passenger.ticket === "firstclass")
{
orderFunction = function()
{
document.write("Would you prefer niffler nuggets or basilisk filet?<br>");
}//end orderfunction;
}// end if firstclass
else if(passenger.ticket === "premium")
{
orderFunction = function()
{
document.write("Do you want bowtruckle wafers or puffskein nuggets?<br>");
}//end orderfunction;
}// end else if premium
else
{
orderFunction = function()
{
document.write("You may choose between pumpkin pasties or cauldron cakes.<br>");
}
}//end else firstclass
return orderFunction;
}//end function dinner order
function pickUpTrash()
{
document.write("Do you have any trash to incinerate?<br>");
}//end function pickUpTrash
function printPassenger(passenger)
{
if (passenger.paid)
console.log(passenger.name + " has paid.");
else
console.log( passenger.name + " has not paid.");
}//end function print passenger
function serveCustomer(passenger)
{
document.write("<br>Good afternoon, " + passenger.name + "<br>");
var getDrinkOrderFunction = createDrinkOrder(passenger);
var getDinnerOrderFunction = createDinnerOrder(passenger);
getDrinkOrderFunction();
getDinnerOrderFunction();
pickUpTrash();
getDrinkOrderFunction();
getDrinkOrderFunction();
getDrinkOrderFunction();
}//end function serveCustomer
function servePassengers(passengers)
{
for (var i = 0; i < passengers.length; i++)
{
serveCustomer(passengers[i]);
}//end for loop
}// end function servePassengers
var allCanFly = processPassengers(passengers, checkNoFlylist);
if(!allCanFly)
{
console.log("The plane can't take off: we have a passenger on the no fly list");
}//end if not all can fly
var allPaid = processPassengers(passengers, checkNotPaid);
if (!allPaid)
{
console.log("The plane can't take off: not all passengers have paid.");
}//end if not all paid
processPassengers(passengers, printPassenger);
servePassengers(passengers);
</script>
</body>
</html>