-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWisecup_Joshua_assignment3.js
193 lines (154 loc) · 4.53 KB
/
Wisecup_Joshua_assignment3.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Joshua Wisecup
// SDI 1211
// Thursday, December 6, 2012
// Assignment - Project 3
// Thanksgiving Holiday Trip Part 3
//alert("JavaScript works!");
// my variables
/*var tripCity = function (name) {
var distance = function (miles) {
return { "name":name,"distance":[] };
}
};*/
var city = [
{
name: "Denver",
distance: 1852,
tripCost: 450,
gasPrices: [
3.25,
3.48,
3.35,
3.28
]
},
{
name: "Germantown",
distance: 125,
tripCost: 120,
gasPrices: [
3.15,
3.14,
3.18,
3.45
]
},
{
name: "Georgetown",
distance: 18,
tripCost: 40,
gasPrices: [
3.10,
3.09,
3.12,
3.25
]
/* calculateGasAvg: function () {
console.log("The average.");
var sum = 0;
for (var i = 0; i < city[2].gasPrices.length; i++) {
sum += parseInt(city[2].gasPrices[i]);
var avg = sum/city[2].gasPrices.length;
console.log("The sum is " + sum + " . The average gas price is $" + avg + " per gallon.");
}
}*/
}
];
var readyForTrip = true;
var checkWeather = true;
var handleData = function (json) {
for (var i = 0; i < json.weatherForecast.length; i++) {
var weatherForecast = json.weatherForecast[i];
console.log("On " + weatherForecast.day + " it will be " + weatherForecast.temperature + " degrees and " + weatherForecast.conditions + ".");
};
var weatherForecastday = json.weatherForecast.day;
if (checkWeather == true) {
console.log("We should leave on Friday.")
};
};
var key = "gasPrices";
var bigTripPlan = function() {
if ( readyForTrip == true) {
console.log("Do we have enough money?");
var moneyOnHand = 500;
if (moneyOnHand >= (city[0].tripCost)) {
console.log("We have $" + moneyOnHand + ". We should go to " + city[0].name + ".")
} else if (moneyOnHand >= (city[1].tripCost)) {
console.log("We have $" + moneyOnHand + ". We should go to " + city[1].name + ".")
} else if (moneyOnHand >= (city[2].tripCost)) {
console.log("We have $" + moneyOnHand + ". We should go to " + city[2].name + ".")
} else {
console.log("Looks like we\'re not going on a trip this year.")
}
return city[0].distance;
};
};
var distanceToDrive = city[0].distance;
var onTheRoad = bigTripPlan();
var milesPerGallon = function(totalMiles, milesPerTank, costPerTank) {
var numberStops;
var totalmiles;
numberStops = Math.floor(totalMiles / milesPerTank);
var costPerStop;
costPerStop = numberStops * costPerTank;
if (numberStops > 0) {
console.log("If our drive is " + totalMiles + " miles, then we will have to stop " + numberStops + " times for gas.");
console.log("That will cost about $" + costPerStop + " in gas for " + numberStops + " stops.");
} else {
console.log("We won't have to fill-up until after we get there.")
};
return numberStops;
};
var motivation = function(driving,message, message1, message2) {
if (driving==true) {
var traveling = ["I am driving."]
console.log(message + message1);
} else {
console.log(message2)
};
return traveling;
};
var milesRemain = function(milesThisTrip, destination) {
for (var miles = 0; miles < milesThisTrip; miles += 300) {
var milesRemain = milesThisTrip - miles;
console.log("We have " + milesRemain + " miles left. We have gone " + miles + " miles.");
while (milesThisTrip > 1851) {
console.log("You are doing a great job!");
milesThisTrip--;
};
}
console.log("We made it to " + destination + ".");
return milesThisTrip;
};
var gasStops = function(destination, numberStops) {
var stopPoints = ["St. Louis, MO", "Odessa, MO", "Kansas City, MO", "Salina, KS", "Hays, KS", "Burlington, CO"];
console.log("On our way to " + destination + " we made " + numberStops + " stops.")
for (var i = 0; i < stopPoints.length; i++) {
console.log("We stopped at " + stopPoints[i] + ". ")
}
console.log("It was a great trip!")
return stopPoints;
};
// my output
handleData(json);
milesPerGallon(distanceToDrive,300,35);
motivation(true, "Now that you've started your trip, stay alert."," Keep up the good work!", "No worries. We\'ll be on the road soon.");
milesRemain(distanceToDrive,(city[0].name));
gasStops((city[0].name), 6);
/*console.log (city);
console.log (city[0].gasPrices);
console.log (city[0]);*/
/*var averageGasPrice = function avgGas() {
for (var i = 0; i < city[0].gasPrices.length; i++) {
var sum = parseInt(city[0].gasPrices[i]);
var avg = sum/city[0].gasPrices.length;
}
return avg;
}
var averageGas=averageGasPrice();
console.log (averageGas);
*/
/*var jsonstring = JSON.stringify(json);
console.log(jsonstring);
var receivedjson = JSON.parse(jsonstring);
console.log(receivedjson); */