diff --git a/index.html b/index.html
index 7bc5d75..4c08dad 100644
--- a/index.html
+++ b/index.html
@@ -118,8 +118,12 @@
return '肥胖';
}
- function row(a, b) {
- return '
| ' + a + ' | ' + b + ' |
';
+ function macroRow(name, pct, grams) {
+ return '| ' + name + ' | ' + pct + ' | ' + grams + ' g |
';
+ }
+
+ function nutriRow(name, value) {
+ return '| ' + name + ' | ' + value + ' |
';
}
function calculate() {
@@ -151,18 +155,18 @@
document.getElementById('rTarget').textContent = Math.round(target);
document.getElementById('macroBody').innerHTML =
- row('碳水化合物', '55%' + carb + ' g | ').replace('55% | ', '15% | ' + protein + ' g | ') +
- row('脂肪', '30%').replace('30%', '30%' + fat + ' g | ');
+ macroRow('碳水化合物', '55%', carb) +
+ macroRow('蛋白质', '15%', protein) +
+ macroRow('脂肪', '30%', fat);
var ref = REF[sex];
document.getElementById('nutriBody').innerHTML =
- row('蛋白质', protein + ' g(优质蛋白占一半以上)') +
- row('脂类(脂肪)', fat + ' g(烹调油 25–30 g,饱和脂肪<10%)') +
- row('碳水化合物', carb + ' g(添加糖<25 g,膳食纤维 25–30 g)') +
- row('维生素', ref.vit) +
- row('矿物质(无机盐)', ref.min) +
- row('水', ref.water);
+ nutriRow('蛋白质', protein + ' g(优质蛋白占一半以上)') +
+ nutriRow('脂类(脂肪)', fat + ' g(烹调油 25–30 g,饱和脂肪<10%)') +
+ nutriRow('碳水化合物', carb + ' g(添加糖<25 g,膳食纤维 25–30 g)') +
+ nutriRow('维生素', ref.vit) +
+ nutriRow('矿物质(无机盐)', ref.min) +
+ nutriRow('水', ref.water);
document.getElementById('result').style.display = 'block';
}