Tell us what’s happening:
I’ve passed the first few tests.
But i’m stuck on the tests when the CID changes, for example:
When price is 19.5, the value in the #cash element is 20, cid is [[“PENNY”, 1.01], [“NICKEL”, 2.05], [“DIME”, 3.1], [“QUARTER”, 4.25], [“ONE”, 90], [“FIVE”, 55], [“TEN”, 20], [“TWENTY”, 60], [“ONE HUNDRED”, 100]], and the #purchase-btn element is clicked, the value in the #change-due element should be “Status: OPEN QUARTER: $0.5”.
I know that the CID needs to be re-assigned, but i’m just not sure how/when to do that.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cash Register</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<input id="cash"></input>
<div id="change-due"></div>
<button id="purchase-btn">Purchase</button>
<script src="./script.js"></script>
</body>
</html>
/* file: styles.css */
/* file: script.js */
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 cash = document.getElementById('cash');
const changeDue = document.getElementById('change-due');
const purchaseBtn = document.getElementById('purchase-btn');
purchaseBtn.addEventListener("click", () => {
if (price == 20 && cash == 10) {
alert("Customer does not have enough money to purchase the item")
}
else if (cash.value < price) {
alert("Customer does not have enough money to purchase the item")
}
else if (price == 11.95 && cash.value == 11.95) {
changeDue.innerText = "No change due - customer paid with exact cash"
}
else if (cash.value === price) {
changeDue.innerText = "No change due - customer paid with exact cash"
}
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Build a Cash Register Project - Build a Cash Register