<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Alex Ion</title>
    <description>The latest articles on Forem by Alex Ion (@alexionel).</description>
    <link>https://forem.com/alexionel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3647630%2F3feb2aed-220a-4d02-b205-514225f8a3eb.png</url>
      <title>Forem: Alex Ion</title>
      <link>https://forem.com/alexionel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alexionel"/>
    <language>en</language>
    <item>
      <title>How I Built a Privacy-First Prediabetes Risk Calculator Using Pure JavaScript (No Backend Needed)</title>
      <dc:creator>Alex Ion</dc:creator>
      <pubDate>Fri, 05 Dec 2025 09:57:18 +0000</pubDate>
      <link>https://forem.com/alexionel/how-i-built-a-privacy-first-prediabetes-risk-calculator-using-pure-javascript-no-backend-needed-2ggf</link>
      <guid>https://forem.com/alexionel/how-i-built-a-privacy-first-prediabetes-risk-calculator-using-pure-javascript-no-backend-needed-2ggf</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffdi7b5r1h9c9c76khs2i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffdi7b5r1h9c9c76khs2i.png" alt=" " width="800" height="591"&gt;&lt;/a&gt;&lt;br&gt;
For a long time, online health tools followed the same pattern:&lt;br&gt;
• long forms&lt;br&gt;
• slow web apps&lt;br&gt;
• mandatory accounts&lt;br&gt;
• and most importantly — data sent to a server.&lt;/p&gt;

&lt;p&gt;I wanted to challenge that.&lt;/p&gt;

&lt;p&gt;What if a user could calculate an educational health score — in this case, prediabetes risk — with zero data leaving their browser?&lt;/p&gt;

&lt;p&gt;No backend.&lt;br&gt;
No analytics.&lt;br&gt;
No requests.&lt;br&gt;
Just a clean JavaScript engine running locally.&lt;/p&gt;

&lt;p&gt;That idea became the foundation of SugarRisk, a fully client-side metabolic risk calculator built with HTML, CSS, and plain JavaScript.&lt;/p&gt;

&lt;p&gt;In this article, I’ll walk through the technical concepts behind the project: how the scoring model works, how the UI updates dynamically, and why running everything locally creates a better privacy experience.&lt;/p&gt;

&lt;p&gt;⭐ Why client-side only?&lt;/p&gt;

&lt;p&gt;Most calculators online use a backend because:&lt;/p&gt;

&lt;p&gt;they store results&lt;/p&gt;

&lt;p&gt;they run machine learning models&lt;/p&gt;

&lt;p&gt;they require user accounts&lt;/p&gt;

&lt;p&gt;they log everything&lt;/p&gt;

&lt;p&gt;But for an educational risk score, none of that is necessary.&lt;/p&gt;

&lt;p&gt;Client-side advantages&lt;/p&gt;

&lt;p&gt;Instant feedback — no network delay&lt;/p&gt;

&lt;p&gt;Zero data exposure — nothing leaves the device&lt;/p&gt;

&lt;p&gt;Lower hosting costs — no backend server&lt;/p&gt;

&lt;p&gt;Better UX — results appear instantly while typing&lt;/p&gt;

&lt;p&gt;Full transparency — users can inspect the scoring model&lt;/p&gt;

&lt;p&gt;This approach also aligns with modern privacy expectations.&lt;/p&gt;

&lt;p&gt;⭐ Project structure&lt;/p&gt;

&lt;p&gt;The entire app is built from only three core files:&lt;/p&gt;

&lt;p&gt;index.html      # Layout + form&lt;br&gt;
script.js       # Scoring engine + interactions&lt;br&gt;
style.css       # UI/UX styling&lt;/p&gt;

&lt;p&gt;And that's it.&lt;/p&gt;

&lt;p&gt;No framework.&lt;br&gt;
No dependencies.&lt;br&gt;
No build step.&lt;/p&gt;

&lt;p&gt;Just clean browser-native code.&lt;/p&gt;

&lt;p&gt;⭐ The scoring model (explained simply)&lt;/p&gt;

&lt;p&gt;Any risk calculator needs:&lt;/p&gt;

&lt;p&gt;Inputs&lt;/p&gt;

&lt;p&gt;Weights&lt;/p&gt;

&lt;p&gt;A scoring formula&lt;/p&gt;

&lt;p&gt;A way to explain results&lt;/p&gt;

&lt;p&gt;SugarRisk uses 15+ inputs such as:&lt;/p&gt;

&lt;p&gt;age&lt;/p&gt;

&lt;p&gt;BMI&lt;/p&gt;

&lt;p&gt;waist circumference&lt;/p&gt;

&lt;p&gt;physical activity&lt;/p&gt;

&lt;p&gt;family history&lt;/p&gt;

&lt;p&gt;blood pressure&lt;/p&gt;

&lt;p&gt;sleep quality&lt;/p&gt;

&lt;p&gt;smoking&lt;/p&gt;

&lt;p&gt;sugary drinks&lt;/p&gt;

&lt;p&gt;fasting glucose (optional)&lt;/p&gt;

&lt;p&gt;A1C (optional)&lt;/p&gt;

&lt;p&gt;Each factor contributes a weighted amount to a total score from 0 to 100.&lt;/p&gt;

&lt;p&gt;For example, here's a simplified version of the waist logic:&lt;/p&gt;

&lt;p&gt;function waistRisk(waist, gender) {&lt;br&gt;
  if (!waist) return 0;&lt;/p&gt;

&lt;p&gt;if (gender === "male") {&lt;br&gt;
    if (waist &amp;lt; 94) return 0;&lt;br&gt;
    if (waist &amp;lt; 102) return 8;&lt;br&gt;
    return 15;&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;if (gender === "female") {&lt;br&gt;
    if (waist &amp;lt; 80) return 0;&lt;br&gt;
    if (waist &amp;lt; 88) return 8;&lt;br&gt;
    return 15;&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Each component returns a partial score.&lt;br&gt;
The total score is the sum of all components:&lt;/p&gt;

&lt;p&gt;let totalRisk =&lt;br&gt;
  ageRisk(age) +&lt;br&gt;
  bmiRisk(bmi) +&lt;br&gt;
  waistRisk(waist, gender) +&lt;br&gt;
  activityRisk(activity) +&lt;br&gt;
  glucoseRisk(fastingGlucose) +&lt;br&gt;
  a1cRisk(a1c) +&lt;br&gt;
  lifestyleRisk(smoking, sugaryDrinks) +&lt;br&gt;
  sleepRisk(sleepQuality);&lt;/p&gt;

&lt;p&gt;Finally, the score is normalized:&lt;/p&gt;

&lt;p&gt;totalRisk = Math.min(100, Math.max(0, totalRisk));&lt;/p&gt;

&lt;p&gt;⭐ Live updating with JavaScript&lt;/p&gt;

&lt;p&gt;One of the nicest UX elements is that the score updates instantly when the user changes an input.&lt;/p&gt;

&lt;p&gt;DEV-friendly code snippet:&lt;/p&gt;

&lt;p&gt;document.querySelectorAll("input, select").forEach(el =&amp;gt; {&lt;br&gt;
  el.addEventListener("input", () =&amp;gt; {&lt;br&gt;
    const score = calculateRisk();&lt;br&gt;
    updateUI(score);&lt;br&gt;
  });&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;The function updateUI() animates the bar and updates the text:&lt;/p&gt;

&lt;p&gt;function updateUI(score) {&lt;br&gt;
  const indicator = document.getElementById("riskIndicator");&lt;br&gt;
  const label = document.getElementById("riskLabel");&lt;/p&gt;

&lt;p&gt;indicator.style.left = &lt;code&gt;${score}%&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;if (score &amp;lt; 34) label.textContent = "Low Risk";&lt;br&gt;
  else if (score &amp;lt; 67) label.textContent = "Moderate Risk";&lt;br&gt;
  else label.textContent = "High Risk";&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;This gives users real-time feedback, which feels much more engaging than submitting a form.&lt;/p&gt;

&lt;p&gt;⭐ Visualizing the score&lt;/p&gt;

&lt;p&gt;The score bar is a simple linear gradient:&lt;/p&gt;

&lt;p&gt;green → yellow → red&lt;/p&gt;

&lt;p&gt;Matching metabolic risk zones.&lt;/p&gt;

&lt;p&gt;CSS example:&lt;/p&gt;

&lt;p&gt;.risk-bar-track {&lt;br&gt;
  height: 10px;&lt;br&gt;
  border-radius: 999px;&lt;br&gt;
  background: linear-gradient(90deg, #22c55e, #fbbf24, #fb7185);&lt;br&gt;
  position: relative;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.risk-bar-indicator {&lt;br&gt;
  position: absolute;&lt;br&gt;
  width: 16px;&lt;br&gt;
  height: 16px;&lt;br&gt;
  border-radius: 999px;&lt;br&gt;
  background: #b91c1c;&lt;br&gt;
  transform: translate(-50%, -50%);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;The result:&lt;/p&gt;

&lt;p&gt;Smooth&lt;/p&gt;

&lt;p&gt;Minimal&lt;/p&gt;

&lt;p&gt;Helps users understand their risk immediately&lt;/p&gt;

&lt;p&gt;⭐ Privacy-first architecture&lt;/p&gt;

&lt;p&gt;This is where devs usually raise an eyebrow:&lt;/p&gt;

&lt;p&gt;“If there’s no backend, how do you store results?”&lt;/p&gt;

&lt;p&gt;Answer:&lt;/p&gt;

&lt;p&gt;You don’t.&lt;br&gt;
There’s no reason for sensitive health information to leave the device.&lt;/p&gt;

&lt;p&gt;No cookies&lt;/p&gt;

&lt;p&gt;No local storage&lt;/p&gt;

&lt;p&gt;No analytics&lt;/p&gt;

&lt;p&gt;No request logs&lt;/p&gt;

&lt;p&gt;No user accounts&lt;/p&gt;

&lt;p&gt;Here’s the actual network tab during use:&lt;/p&gt;

&lt;p&gt;(empty)&lt;/p&gt;

&lt;p&gt;The scoring happens entirely inside a pure function:&lt;/p&gt;

&lt;p&gt;function calculateRisk() {&lt;br&gt;
  // returns a number 0–100&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Users can also inspect how everything works — something impossible in black-box medical apps.&lt;/p&gt;

&lt;p&gt;⭐ Lessons learned&lt;/p&gt;

&lt;p&gt;Building this tool taught me a few things:&lt;/p&gt;

&lt;p&gt;✔ You don’t need a backend for everything&lt;/p&gt;

&lt;p&gt;We often default to servers even when logic can run client-side.&lt;/p&gt;

&lt;p&gt;✔ Transparency builds trust&lt;/p&gt;

&lt;p&gt;Users appreciate seeing that no data leaves their browser.&lt;/p&gt;

&lt;p&gt;✔ Simplicity &amp;gt; complexity&lt;/p&gt;

&lt;p&gt;No frameworks = fast loading = great UX.&lt;/p&gt;

&lt;p&gt;✔ Health-tech needs privacy-first tools&lt;/p&gt;

&lt;p&gt;People are more likely to use health calculators when they know their data isn’t sent anywhere.&lt;/p&gt;

&lt;p&gt;⭐ Try the demo&lt;/p&gt;

&lt;p&gt;If you want to see the calculator in action:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://sugarrisk.com" rel="noopener noreferrer"&gt;https://sugarrisk.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can view everything in DevTools — logic, UI, requests (or rather, the lack of them).&lt;/p&gt;

&lt;p&gt;⭐ Final thoughts&lt;/p&gt;

&lt;p&gt;This project started as a small experiment:&lt;/p&gt;

&lt;p&gt;Can an educational health tool run entirely in the browser with zero data collection?&lt;/p&gt;

&lt;p&gt;The answer was yes.&lt;/p&gt;

&lt;p&gt;And I think we’ll see more privacy-focused micro-apps like this — fast, transparent, and user-friendly — especially as people become more aware of how their health data is used.&lt;/p&gt;

&lt;p&gt;If you have ideas, improvements, or want to build something similar, feel free to connect. I'm always open to health-tech discussions.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>privacy</category>
      <category>healthcare</category>
    </item>
  </channel>
</rss>
