From 4507895714b4cbb4ddd55bb7a75ec9a0df72849f Mon Sep 17 00:00:00 2001 From: cyfraeviolae Date: Thu, 12 Jan 2023 18:03:36 -0500 Subject: js --- static/script.js | 70 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/static/script.js b/static/script.js index ced777c..28353cd 100644 --- a/static/script.js +++ b/static/script.js @@ -1,27 +1,47 @@ "use strict"; -var html = `` -for (var table in data) { - var s = `` - for (var idx in data[table]) { - let tag = table + '|' + idx - s += ` - ` +let form = null; +let nutrition = null; +console.log('bye') + +window.onload = function(evt) { + console.log('hi') + var html = `` + for (var table in data) { + var s = `` + for (var idx in data[table]) { + let tag = table + '|' + idx + s += ` + ` + } + html += `
${table}${s}
` } - html += `
${table}${s}
` + html += `
Dressing amount + +
+ +
+ +
+
` + + nutrition = document.getElementById('nutrition') + form = document.getElementById('form') + form.innerHTML = html + + form.addEventListener('change', function() { + let total = calculateNutrition() + var s = ` + Calories: ${total.calories}
+ Carbohydrates (g): ${total.total_carbs}
+ Dietary fiber (g): ${total.dietary_fiber}
+ Fat (g): ${total.total_fat}
+ Protein (g): ${total.protein}
+ ` + nutrition.innerHTML = s + }) } -html += `
Dressing amount - -
- -
- -
-
` -nutrition = document.getElementById('nutrition') -form = document.getElementById('form') -form.innerHTML = html let multipliers = {'none': 0, 'light': 1, 'medium': 2, 'heavy': 3} @@ -54,15 +74,3 @@ function calculateNutrition() { } return total } - -form.addEventListener('change', function() { - let total = calculateNutrition() - var s = ` - Calories: ${total.calories}
- Carbohydrates (g): ${total.total_carbs}
- Dietary fiber (g): ${total.dietary_fiber}
- Fat (g): ${total.total_fat}
- Protein (g): ${total.protein}
- ` - nutrition.innerHTML = s -}) -- cgit v1.2.3