Skip to content

Commit 1cd23c5

Browse files
complete
1 parent f84a713 commit 1cd23c5

File tree

4 files changed

+3587
-22
lines changed

4 files changed

+3587
-22
lines changed

more-on-functions/exercises/raid-a-shuttle.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ function checkFuel(level) {
88
}
99
}
1010

11+
//KT - why would I put this anywhere? it prints the amount. I would want it to return the amount somewhere and the color here.
12+
let definetlyTheShuttleFuelLevel = function(n) {
13+
if (checkFuel(n) === "green") {
14+
return (n - 100001);
15+
} else if (checkFuel(n) === "yellow") {
16+
return (n - 50001);
17+
} else {
18+
return (n);
19+
}
20+
}
21+
//console.log(definetlyTheShuttleFuelLevel(55000));
22+
1123
function holdStatus(arr){
1224
if (arr.length < 7) {
1325
return `Spaces available: ${7-arr.length}.`;
@@ -28,6 +40,18 @@ console.log("Hold status: " + holdStatus(cargoHold));
2840
*/
2941

3042
//a). Define an anonymous function and set it equal to a variable with a normal, non-suspicious name. The function takes one parameter. This will be the fuel level on the shuttle.
43+
/*
44+
let definetlyTheShuttleFuelLevel = function(n) {
45+
if (checkFuel(n) === "green") {
46+
return (n - 100001);
47+
} else if (checkFuel(n) === "yellow") {
48+
return (n - 50001);
49+
} else {
50+
return (n);
51+
}
52+
}
53+
*/
54+
//console.log(definetlyTheShuttleFuelLevel(55000));
3155

3256
//b). You must siphon off fuel without alerting the TAs. Inside your function, you want to reduce the fuel level as much as possible WITHOUT changing the color returned by the checkFuel function.
3357

@@ -39,6 +63,14 @@ console.log("Hold status: " + holdStatus(cargoHold));
3963
*/
4064

4165
//a). Define another anonymous function with an array as a parameter, and set it equal to another innocent variable.
66+
let holdStats = function([]) {
67+
stolenGoods = (cargoHold.splice((cargoHold.indexOf("gold")),1,"metal"));
68+
stolenGoods.push(cargoHold.splice((cargoHold.indexOf("meal kits")),1,"meel"));
69+
return cargoHold;
70+
}
71+
72+
console.log(holdStats(cargoHold));
73+
console.log(stolenGoods);
4274

4375
//b). You need to swipe two items from the cargo hold. Choose well. Stealing water ain’t gonna get us rich. Put the swag into a new array and return it from the function.
4476

@@ -50,7 +82,18 @@ console.log("Hold status: " + holdStatus(cargoHold));
5082
*/
5183

5284
//a). Define a function called irs that can take fuelLevel and cargoHold as arguments.
53-
85+
let irs = function(fuelLevel,cargoHold){
86+
return `Took ${definetlyTheShuttleFuelLevel(fuelLevel)}kg of fuel and ${stolenGoods[0]} and ${stolenGoods[1]} from the cargo hold. The remaining cargo hold is ${holdStats(cargoHold)}.`
87+
}
88+
89+
5490
//b). Call your anonymous fuel and cargo functions from within irs.
5591

56-
//c). Use a template literal to return, "Raided _____ kg of fuel from the tanks, and stole ____ and ____ from the cargo hold."
92+
//c). Use a template literal to return, "Raided _____ kg of fuel from the tanks, and stole ____ and ____ from the cargo hold."
93+
94+
console.log(irs(fuelLevel,cargoHold));
95+
96+
//KT - not sure why I'm getting meel twice on the output
97+
//KT - I'm not sure how to do step 4, liberating the cargo
98+
// and collect a new array I can use in the template literal
99+
// or how to make it general so it just picks the best things for me

0 commit comments

Comments
 (0)