Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Background: The first step in brewing beer is to extract sugars from grains by soaking the grains in hot water. This step is called mashing,
Background: The first step in brewing beer is to extract sugars from grains by soaking the grains in hot water. This step is called mashing, and the resulting sugar-water is called wort. Each variety of grain contributes a different amount of sugar (the grain's yield) to the wort. Calculating the final amount of sugar in the wort is an important part of designing a beer recipe, since the sugars will later ferment into alcohol. To measure the amount of sugar in the wort we use specific gravity (SG), a decimal number (e.g., 1.054) which represents the ratio of the sugar-water's density to that of pure water (1.000 SG). Specific gravity measurements during the brewing process are typically between about 1.010 and 1.100 Your job is to write the JavaScript code to add behavior to the following page, which estimates the specific gravity of a list of user-entered grains: Mash-It! HTML:
Malt bill
Add another grain Calculate SG id="calculate">Calculate SG Estimated Specific Gravity: 1.068 assumes a 5.5 gallon batch)
Estimated Specific Gravit span>
(assumes a 5.5 gallon batch)
The page consists of a table in which the user can enter grains. Every time the Add another grain button is clicked,a new row should be added at the bottom of the table. Each row consists of three text-entry fields, each in its own table cell, for entering the following values: an amount (in pounds), a name, and a sugar ield (in PPG"). These entry fields should have the classes amount, name, and yield respectively When the Calculate SG button is pressed, your code should estimate the specific gravity of the user-entered grains by performing the following calculation SGe round([ay, ta2y2++ay,] / 5.5)/1000 +1 (Where ai and yi represent the amount and yield of the first grain, and so on.) In other words, for each grain in the list, multiply its amount (the number in the "lbs" column) by its yield (the number in the "PPG" column), and take the sum of these products. Then divide that by 5.5 (which represents the volume of water it's dissolved in, in gallons). Round the result to the nearest integer, then to express it as a number 1 followed by 3 decimal places (e.g., 1.054), divide by 1000 and add 1 For example, using the values in the above screenshot, your calculation would be as follows: SGe round ([8.5 38 +.5-32 .5 34 + .5 -34] / 5.5) /1000 +1-1.068 You should assume all input to text boxes is valid; that is, reasonable values will always be entered in the fields for amount and yield. You may assume the Prototype JavaScript library is loaded prior to your script being loaded. When injecting content into the page, you may use the innerHTML property for injecting plain text only; you may not use it to inject any HTML code (assumes a 5.5 gallon batch)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started