Skip to content

Commit

Permalink
Add couscous calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
kittsville committed Jul 3, 2024
1 parent 070b169 commit 87347cc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
29 changes: 29 additions & 0 deletions couscous-calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Couscous Calculator
tagline: Calculate couscous/water ratio
layout: default
---

<label class="mdc-text-field mdc-text-field--outlined">
<span class="mdc-notched-outline">
<span class="mdc-notched-outline__leading"></span>
<span class="mdc-notched-outline__notch">
<span class="mdc-floating-label" id="couscous-label-id">Couscous</span>
</span>
<span class="mdc-notched-outline__trailing"></span>
</span>
<input id="couscous" type="number" class="mdc-text-field__input" aria-labelledby="couscous-label-id" value="250">
<span class="mdc-text-field__affix mdc-text-field__affix--suffix">g</span>
</label>

<label class="mdc-text-field mdc-text-field--outlined">
<span class="mdc-notched-outline">
<span class="mdc-notched-outline__leading"></span>
<span class="mdc-notched-outline__notch">
<span class="mdc-floating-label" id="water-label-id">Water</span>
</span>
<span class="mdc-notched-outline__trailing"></span>
</span>
<input id="water" type="number" class="mdc-text-field__input" aria-labelledby="water-label-id" value="313">
<span class="mdc-text-field__affix mdc-text-field__affix--suffix">ml</span>
</label>
16 changes: 16 additions & 0 deletions couscous-calculator/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const waterEl = document.getElementById('water');
const couscousEl = document.getElementById('couscous');

const ratio = 100 / 125;

waterEl.addEventListener('input', () => {
const waterQuantity = parseInt(waterEl.value, 10);
const lentilQuantity = waterQuantity * ratio;
couscousEl.value = Math.round(lentilQuantity);
});

couscousEl.addEventListener('input', () => {
const lentilQuantity = parseInt(couscousEl.value, 10);
const waterQuantity = lentilQuantity / ratio;
waterEl.value = Math.round(waterQuantity);
});
14 changes: 14 additions & 0 deletions couscous-calculator/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.mdc-text-field {
margin: 0.5rem;
width: 7rem;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}

input[type=number] {
-moz-appearance:textfield;
}

0 comments on commit 87347cc

Please sign in to comment.