Tell us what’s happening:
I made all this, and now im stuck, i dont know how to write for, how to search, what, and how much to subsctract from input.value, or should i subsctract from it at all?I dont know what do i even do, i feel so ass about my skills
Your code so far
<!-- file: index.html -->
/* file: script.js */
const status = document.getElementById('status');
const input = document.getElementById('cash');
const output = document.getElementById('change-due');
const purchaseBtn = document.getElementById('purchase-btn');
let price = 1.87;
let cid = [
['PENNY', 1.01],
['NICKEL', 2.05],
['DIME', 3.1],
['QUARTER', 4.25],
['ONE', 90],
['FIVE', 55],
['TEN', 20],
['TWENTY', 60],
['ONE HUNDRED', 100]
];
const denominations = [
['ONE HUNDRED', 100],
['TWENTY', 20],
['TEN', 10],
['FIVE', 5],
['ONE', 1],
['QUARTER', 0.25],
['DIME', 0.1],
['NICKEL', 0.05],
['PENNY', 0.01]
];
const checkResults = () => {
const cash = parseFloat(input.value);
const changeNeeded = (cash - price).toFixed(2);
if (cash < price) {
alert("Customer does not have enough money");
return;
}
if (cash === price) {
output.textContent = "No change needed";
return;
}
let remainingChange = changeNeeded;
const changeBreakdown = [];
const tempCid = [...cid].reverse();
for (const [name, value] of denominations) {
if(input.value >= value){
input.value -= value;
}
}
}
purchaseBtn.addEventListener("click", checkResults)
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 OPR/115.0.0.0
Challenge Information:
Build a Cash Register Project - Build a Cash Register