Hello everyone!
I’ve been having this problem with cash register project.
Due to the conditions I’ve been provided with price and cid variables, which are declared in the global scope.
But the console keeps giving me a reference error (price is not defined) even though it is defined in a global scope, and therefore, should be available within all the functions. It still doesn’t work even if I pass it as an argument. It still doesn’t work even if I declare it inside my handle function.
Seems like tests just don’t see it.
Pretty stupid situation, and I am out of ideas.
Maybe somebody had the same problem?
If you share your code, we can try to help you debug it.
Here is my code. Here I passed price, cash and cid as arguments, but it still doen’t work if I don’t.
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 button = document.getElementById('purchase-btn');
const changeDue = document.getElementById('change-due');
const handlePayment = (price, cash, cid) => {
console.log(cash)
const currentCash = Number(cash.value);
if (currentCash < price) {
alert('Customer does not have enough money to purchase the item')
} else if (currentCash === price) {
changeDue.innerText = 'No change due - customer paid with exact cash';
} else if (currentCash > price) {
let rest = currentCash - price;
}
}
button.addEventListener('click', () => {
handlePayment(price, cash, cid);
})
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.