0

Html and js

I've created a function call using a button/onclick within my html but I cannot get it to work? Any advice please: <button onclick="calculateInsulinBolus()"> calculateInsulinBolus(carbohydrates,carbToInsulinRatio,currentBloodGlucose,targetBloodGlucose,insulinSensitivityFactor); {   carbohydrates = parseFloat(carbohydrates);   carbToInsulinRatio = parseFloat(carbToInsulinRatio);   currentBloodGlucose = parseFloat(currentBloodGlucose);   targetBloodGlucose = parseFloat(targetBloodGlucose);   insulinSensitivityFactor = parseFloat(insulinSensitivityFactor); const carbohydrateBolus = carbohydrates/carbToInsulinRatio; const correctionBolus = (currentBloodGlucose - targetBloodGlucose) /   insulinSensitivityFactor; const totalInsulinBolus = carbohydrateBolus+ correctionBolus; return totalInsulinBolus; }

25th Aug 2024, 7:41 PM
Shane Farrow
Shane Farrow - avatar
8 Antworten
+ 3
The issue is that you are not rendering the value anywhere. You can do console.log(totalInsulinBolus) amd see the final value. You can see the value on the screen if you do document.write(totalInsulinBolus) or append it inside a paragraph
25th Aug 2024, 8:59 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 3
Shane Farrow maybe something like this? I don't know what the default or reasonable values and units should be, though, or if the calculations are correct. You should modify them yourself. https://sololearn.com/compiler-playground/Wav047iLgJ21/?ref=app
25th Aug 2024, 11:36 PM
Bob_Li
Bob_Li - avatar
+ 2
What error are you getting? Also, could you provide a link woth your code? It would be easier to help that way
25th Aug 2024, 8:23 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 2
🍇 Alex Tușinean 💜 that worked thank you. Bob_Li thanks, I have taken some inspiration in the layout from this one now and it has much improved my own.
26th Aug 2024, 2:51 AM
Shane Farrow
Shane Farrow - avatar
0
Hey Alex, thanks for coming back. I'm just running the code through an online compiler at present while getting it correct. Basically nothing happens when using the calculator, I can complete all the input fields but when the button is pressed nothing at all happens. I'm at a loss. I've run it through jshint and all seems good??
25th Aug 2024, 8:51 PM
Shane Farrow
Shane Farrow - avatar
0
Brilliant, thank you I will try this in the morning. 🤙
25th Aug 2024, 9:15 PM
Shane Farrow
Shane Farrow - avatar
0
Bonjour
27th Aug 2024, 5:26 AM
DIARRA
DIARRA - avatar
0
Hello DIARRA
27th Aug 2024, 5:28 AM
Shane Farrow
Shane Farrow - avatar