A. Download the HTML file js_asmt02.html.
B. The js_asmt02.html contains a recipe for SPAM musubi. There are number inputs for the number of servings and ingredients, as well as a button input to reset the recipe.
C. Change the filename to js_Lastname_02.html, where Lastname is your last name.
D. Open js_Lastname_02.html in Atom to make changes and in a browser to view those changes.
E. At the bottom of js_Lastname_02.html, indicated by an HTML comment, create a script tag to import an external JavaScript file named js02-Lastname-logic.js, where Lastname is your last name.
F. Save js_Lastname_02.html, that is all you will be doing in the HTML file.
G. Create a new file and save it as js02-Lastname-logic.js, where Lastname is your last name. This JavaScript file will contain all the behaviors for the page.
H. In js02-Lastname-logic.js you will be adding an event to all the inputs in js_Lastname_02.html. There are a total of 5 input elements (4 number and 1 button), therefore you will be adding 5 events. Add all events using the addEventListener method.
1. Get each input element and assign them to a variable. All inputs have an id attribute making getting an element convenient. You should have 5 variables.
2. Declare and initialize 4 variables to store the original values of each number input. When you first open js_Lastname_02.html in the browser, the numbers you see are the original, default values. You will use these to calculate the new proportion ratio and assign the new quantities for the ingredients and serving amount.
3. Before moving on, you should have a total of 9 variables at the beginning of the JavaScript file.
4. Add functionality to the Reset button by adding a click event to it that does the following:
5. Ensure the reset button functions properly on the page before moving on. Change any of the numbers on the page then click on the reset button. The numbers should revert to their original values.
6. Next, you will be adding a change event to each of the number input elements so that if the user changes any of the numbers in the recipe, all other numbers will change proportionally. Keep in mind the following:
7. Start by adding a change event to the inputServings element. When the user changes the number of servings, the event function will do 2 main things:
8. Ensure the change event for the servings works properly before moving on. Change the number of servings on the page and verify the SPAM, nori, and rice ingredients change proportionally.
9. Repeat for the other 3 number inputs by adding change events to the SPAM, nori, and rice elements. Ensure each event works before moving on to the next.
I. Comments are not required for this assignment.
js_asmt02.html
< !doctype html >
< html >
< head >
< meta charset="utf-8" >
< title >ICS 215 JavaScript 02< /title >
< !-- JavaScript Assignment 02 -- >
< !-- Created by: Ed Meyer -- >
< link href="https://laulima.hawaii.edu/x/f67OqE" rel="stylesheet" type="text/css" >
< /head >
< body >
< div id="container" >
< header >
< img src="https://laulima.hawaii.edu/x/rTJXrh" > Happy Fun SPAM Musubi Recipe < img src="https://laulima.hawaii.edu/x/VPicgS" >
< /header >
< div id="content" >
< p >Recipe adapted from: < a href="https://www.favfamilyrecipes.com/musubi/" target="_blank" >https://www.favfamilyrecipes.com/musubi/< /a >< /p >
This recipe makes < input type="number" id="inputServings" value="8" min="0" >
musubi(s).
< input type="button" id="resetRecipe" value="Reset" >
< h2 >Ingredients:< /h2 >
< blockquote >
< input type="number" id="inputCanSpam" value="1" min="0" > (12 ounce) can of SPAM< br >
< input type="number" id="inputNori" value="4" min="0" >
sheet(s) Nori (8 1/4" x 4")< br >
< input type="number" id="inputRice" value="6" min="0" > cup(s) cooked rice < br >
< /blockquote >
< h2 >Directions:< /h2 >
< blockquote >
For this recipe, you will need a musubi mold.< br >< br >
Slice the SPAM into about 8-10 slices (depending on how thick you like it).< br >
< br >
Fry SPAM on each side over medium heat until slightly crispy or until desired doneness.< br >< br >
Cut each sheet of nori in half, length wise. Place a strip of nori on a cutting board or clean surface (shiny side down). Place your musubi mold across the middle of the nori. Add rice to the mold, pressing down firmly and evenly, so there is about 1-1 1/2 inches of rice. (dip the mold and your fingers in water as you go to prevent sticking) < br >< br >
Next, remove the mold from the rice. Now you will have a nice little block of rice right on the nori. Add some of the cooked spam to the top. Wrap up one side of the nori and stick it to the top of the SPAM, then wrap up the other side. Just like you are wrapping a nice little package. Use a little water on your finger to seal if needed. Serve warm.< /blockquote >
< /div >
< footer >JavaScript 02 Assignment< /footer >
< !-- Import your js02-Lastname-logic.js file here. -- >
< /div >
< /body >
< /html >