Skip to content

Commit 2848714

Browse files
author
Edward King
committed
updated exercise
1 parent 6adb4fb commit 2848714

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

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

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function holdStatus(arr){
1818
}
1919
}
2020

21-
let fuelLevel = 200000;
21+
let fuelLevel = 1000000;
2222
let cargoHold = ['meal kits', 'space suits', 'first-aid kit', 'satellite', 'gold', 'water', 'AE-35 unit'];
2323

2424
console.log("Fuel level: " + checkFuel(fuelLevel));
@@ -34,24 +34,58 @@ console.log("Hold status: " + holdStatus(cargoHold));
3434
//c). Once you figure out how much fuel to pump out, return that value.
3535
3636
//d). Decide where to best place your function call to gather our new fuel.
37+
*/
38+
let nonSuspiciousFunction = function(a) {
39+
if (checkFuel(a) === 'green') {
40+
return a - 100001;
41+
}
42+
else if (checkFuel(a) === 'yellow') {
43+
return a - 50001;
44+
}
45+
else {
46+
return a;
47+
}
48+
};
49+
50+
let misplacedFuel = nonSuspiciousFunction(fuelLevel);
51+
console.log(misplacedFuel);
3752

3853
/* Next, liberate some of that glorious cargo.
39-
* /
54+
4055
4156
//a). Define another anonymous function with an array as a parameter, and set it equal to another innocent variable.
4257
4358
//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.
4459
4560
//c). The cargo hold has better security than the fuel tanks. It counts how many things are in storage. You need to replace what you steal with something worthless. The count MUST stay the same, or you’ll get caught and thrown into the LaunchCode brig.
4661
47-
//d). Don’t get hasty, matey! Remember to test your function.
62+
//d). Don’t get hasty, matey! Remember to test your function.*/
63+
64+
let lostAndFoundCargo = function (array) {
65+
let acqiredCargo = [];
66+
if (array.includes("gold") || array.includes("satellite")) {
67+
acqiredCargo.unshift("gold", "satellite");
68+
// array.splice().indexOf("gold", "satellite")
69+
}
70+
if (array.includes("gold") || array.includes("satellite")){
71+
array.splice(array.indexOf("gold"));
72+
array.splice(array.indexOf("satellite"));
73+
array.unshift("potatoes", "sneakers");
74+
}
75+
return acqiredCargo;
76+
}
77+
let newStuff = lostAndFoundCargo(cargoHold);
78+
console.log(newStuff);
79+
console.log(cargoHold);
80+
81+
//Finally, you need to print a receipt for the accountant. Don’t laugh! That genius knows MATH and saves us more gold than you can imagine.
82+
4883

49-
/* Finally, you need to print a receipt for the accountant. Dont laugh! That genius knows MATH and saves us more gold than you can imagine.
50-
* /
5184

5285
//a). Define a function called irs that can take fuelLevel and cargoHold as arguments.
5386

5487
//b). Call your anonymous fuel and cargo functions from within irs.
5588

5689
//c). Use a template literal to return, "Raided _____ kg of fuel from the tanks, and stole ____ and ____ from the cargo hold."
5790

91+

0 commit comments

Comments
 (0)