I'm trying to code a calculator that reacts to some tick boxes. The serving size will be multiplied by the different values in the tables below depending on which boxes are ticked. For example, in the ThickChiaYogurt table, 'Thick' is chosen in consistency, the 'Chia' tickbox is selected and the 'Yogurt' tickbox is selected.
The problem I'm having is that I can't seem to get it to do anything with the values.
Here's what the selection box code looks like:
<p>
<label style="font-family: arial" for="textfield">Serving Size (ml):</label>
<input type="text" name="textfield" id="ServingSize"> <?p>
<table width="250">
<tr>
<td><label style="font-family: arial">
<input type="checkbox" name="Settings" value="ChiaUsed" id="Chia">
Use Chia Seeds?</label></td>
</tr>
<tr>
<td><label style="font-family: arial">
<input type="checkbox" name="Settings_" value="YogurtUsed" id="Yogurt">
Use Yogurt?</label></td>
</tr>
<tr>
<td><label style="font-family: arial">
<input type="checkbox" name="Settings_" value="ProteinUsed" id="Protein">
Use Protein / Choc powder?</label></td>
</tr>
<p style="font-family: arial"> Consistency: <select><option>Thick</option>
<option>Medium</option>
<option>Runny</option></select> </p>
And the information I'm going to use against it:
var ThickChiaYogurt = [0.1, 0.38, 0.036, 0.43]
var MediumChiaYogurt = [0.1, 0.42, 0.036, 0.39]
var RunnyChiaYogurt= [0.08, 0.46, 0.036, 0.35]
// var NO CHIA = [ OATS, MILK, GREEK ]
var ThickYogurt = [0.15, 0.38, 0.45]
var MediumYogurt = [0.1, 0.42, 0.41]
var RunnyYogurt = [0.08, 0.46, 0.37]
// var NO GREEK = [ OATS, MILK, CHIA ]
var ThickChia = [0.23, 0.58, 0.036]
var MediumChia = [0.18, 0.61, 0.36 ]
var RunnyChia = [0.16, 0.64, 0.03 ]
// var NO GREEK OR CHIA = [ OATS, MILK ]
var Thick = [0.25, 0.6]
var Medium = [0.22, 0.63]
var Runny = [0.2, 0.65]
var Serving = 111
// OATS MILK GREEK CHIA POWDERS
var Output = [0, 0, 0, 0, 0]
function myFunction(Thick, Serving) {
return Thick[0] * Serving; }
Am I being dumb? It's my first day with JavaScript, so I feel like I'm hitting my head against a wall a bit.
I want it to tell users how much of each ingredient they should use after they've written in how big a serving they want and ticked the relevant boxes.
Thanks!
Aucun commentaire:
Enregistrer un commentaire