Question: Here is the javascript code. After the code are the tasks that need to be added to this code. This is my third attempt before

Here is the javascript code. After the code are the tasks that need to be added to this code. This is my third attempt before i just give up trying to get help with this problem.

function checkFuel(level) {

if (level > 100000){

return 'green';

} else if (level > 50000){

return 'yellow';

} else {

return 'red';

}

}

function holdStatus(arr){

if (arr.length < 7) {

return `Spaces available: ${7-arr.length}.`;

} else if (arr.length > 7){

return `Over capacity by ${arr.length-7} items.`;

} else {

return "Full";

}

}

let fuelLevel = 200000;

let cargoHold = ['meal kits', 'space suits', 'first-aid kit', 'satellite', 'gold', 'water', 'AE-35 unit'];

console.log("Fuel level: " + checkFuel(fuelLevel));

console.log("Hold status: " + holdStatus(cargoHold));

Here is what needs to be added to the code above:

First, steal some fuel from the shuttle.

  1. Define an anonymous function and set it equal ter a variable with the normal, non-suspicious name of parrotFood. The function needs one parameter, which will be the fuel level on the shuttle.
  2. Ye must siphon off fuel without alerting the TAs. Inside yer function, ye want to reduce the fuel level as much as possible WITHOUT changing the color returned by the checkFuel function.
  3. Once ye figure out how much fuel ter pump out, return that value.
  4. Be sure to test yer function! Those bilge rat TAs will notice if they lose too much fuel.

Next, liberate some of that glorious cargo.

  1. Define another anonymous function with an array as a parametarrrrr, and set it equal to another innocent variable, deckMops.
  2. Ye need to swipe two items from the cargo hold. Choose well. Stealing water ain't gonna get us rich. Look fer smaller tech or valuable items that we kin sell like ['dilithium', 'gold', 'AE-35 unit', 'Legos', 'TI-89 calculator'].
  3. Put the swag into a new array and return it from the function.
  4. The cargo hold has better security than the fuel tanks. It counts how many things are in storage. Ye need to replace what ye steal with something worthless. The count MUST stay the same, or ye'll get caught and thrown into the LaunchCode brig.
  5. Don't get hasty, swabbie! Remember to test yer function.

Finally, ye need to print a receipt for the accountant.

Don't laugh! That genius knows MATH and saves us more gold than ye can imagine.

Define a function called irs that takes fuelLevel and cargoHold as parametarrrrrs.

  1. Call parrotFood and deckMops from within irs.
  2. Use a template literal to return, "Raided _____ kg of fuel from the tanks, and stole ____ and ____ from the cargo hold."

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!