Now that we've launched our shuttle, let's use loops (iteration) to automate some tasks.
Fork this repl to start coding. Before you dive in, you might notice that we have several files and folders inside.
Your work will go into
solution.js, but please feel free to explore the program and please don't edit anything outside
solution.js, use the variables provided to store the following arrays.
['chicken', 'pork', 'tofu', 'beef', 'fish', 'beans']
['rice', 'pasta', 'corn', 'potato', 'quinoa', 'crackers']
['peas', 'green beans', 'kale', 'edamame', 'broccoli', 'asparagus']
['juice', 'milk', 'water', 'soy milk', 'soda', 'tea']
['apple', 'banana', 'more kale', 'ice cream', 'chocolate', 'kiwi']
mealAssembly(), write a
for loop to assemble
The meals must include one item from each category in the
The computer needs to know how many crew members to prepare food for and what ingredients. Consider creating a nested loop that will create a meal for each crew member and then add it into a larger collection of meals.
Each ingredient can only be used ONCE.
Add each meal to the
meals array once it is assembled.
To test your own solution, scroll down to another function defined in this file called
runProgram(). Uncomment the lines that call the
mealAssembly function and print the result. Use the repl.it 'Run' button as usual to see your results printed to the console.
askForNumber() to add user input and validation.
whileloop, ask the user to select the number of meals to assemble. Validate the input to make sure it is an integer from 1 - 6.
numMealsvariable returned by the function.
runProgram()function in the file and uncommenting the section labelled for testing Part B.
If you want to make sure that you have checked all the boxes, run the following command in your shell on replit.
This command runs the Jasmine tests that are checking your work for you. If you have a test that fails, check out the name of the test to get a hint as to what you are missing. If you need a refresher on how running the tests works, check out the appendix on Tested Code.
Working and living aboard this amazing space shuttle requires you to pay the utmost attention to cybersecurity. Once you are done working on the meal system, you are prompted to create a new password that will be used for the next 24 hours. Having run out of strong password ideas, your shuttle captain has encouraged you to make a password generator for yourself.
Write your code inside
for loop that combines the two strings together, alternating the characters from each source, and saves the combined string to the
string1 = "1234"and
string2 = "5678", then the output will be "15263748".
string1 = "ABCDEF"and
string2 = "notyet", then the output will be "AnBoCtDyEeFt".
string1 = "LoOt"and
string2 = "oku!", then the output will be "LookOut!".