JSFiddle - React, Tailwind, and code Playground
by Aleem Mohamed
HTML
<div>
Select items for purchase:
<select>
<option>Egg</option>
<option>Bread</option>
<option>Milk</option>
<option>Cheese</option>
</select>
<br>
<br>
<label>
Enter Quantity:
<input></input>
</label>
<br>
<br>
<button>Calculate Total</button>
<p>
Your Total:
<span id="showTotal"></span>
</p>
</div>
JavaScript
var cashRegister = {
total: 0,
add: function(itemCost) {
this.total += itemCost;
},
scan: function(item,quantity) {
switch(item)
case "Egg": this.add(1 * quantity);
case "Bread": this.add(2 * quantity);
case "Milk": this.add(3 * quantity);
case "Cheese": this.add(4 * quantity
}
}
function calculateTotal() {
}