Tell us what’s happening: The last test fails even tho the output exactly matches the test expectations, this is my output:
Status: CLOSED PENNY: $0.5
I had heard on another thread here that this last test had a bug on fcc’s end, but that maybe it had been fixed by now?
If any more of my project info is needed let me know, thanks.
Your code so far
WARNING
The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.
You will need to take an additional step here so the code you wrote presents in an easy to read format.
Please copy/paste all the editor code showing in the challenge from where you just linked.
let price = 19.50;
let cid = [
["PENNY", 0.50],
["NICKEL", 0.00],
["DIME", 0.00],
["QUARTER", 0.00],
["ONE", 0],
["FIVE", 0],
["TEN", 0],
["TWENTY", 0],
["ONE HUNDRED", 0]
];
let cash = 0.0;
let messages = ["Status: OPEN", "Status: CLOSED", "Status: INSUFFICIENT_FUNDS"];
let cond = 0;
let change = 0.0;
let drawer = 0.0;
let str = "";
let numberOfUnits = 0;
let multiplier = Float32Array.from([0.01, 0.05, 0.1, 0.25, 1.0, 5.0, 10.0, 20.0, 100.0]);
let purchaseBtn = document.getElementById("purchase-btn");
let unit = Int32Array.from([0, 0, 0, 0, 0, 0, 0, 0, 0]);
let changeDue = document.getElementById("change-due");
let itemPrice = document.getElementById("item-price");
let denominant = document.getElementById("change");
let clearBtn = document.getElementById("clear-btn");
let numIn = document.getElementById("cash");
changeDue.setAttribute("readonly", true);
itemPrice.setAttribute("readonly", true);
let elements = [document.getElementById("giveP"), document.getElementById("giveN"), document.getElementById("giveD"), document.getElementById("giveQ"),
document.getElementById("giveR"), document.getElementById("giveF"), document.getElementById("giveE"), document.getElementById("giveT"),
document.getElementById("giveH"), document.getElementById("amountP"), document.getElementById("amountN"), document.getElementById("amountD"),
document.getElementById("amountQ"), document.getElementById("amountR"), document.getElementById("amountF"), document.getElementById("amountE"),
document.getElementById("amountT"), document.getElementById("amountH"), document.getElementById("haveP"), document.getElementById("haveN"),
document.getElementById("haveD"), document.getElementById("haveQ"), document.getElementById("haveR"), document.getElementById("haveF"),
document.getElementById("haveE"), document.getElementById("haveT"), document.getElementById("haveH")];
document.addEventListener('DOMContentLoaded', () => {
populator();
});
function populator() {
drawer = 0;
for(let i=0;i<3;i++) {
for(let j=0;j<9;j++) {//i=0 is # to give of each, i=1 is cash value, i=3 # have of each
if (i == 0) {elements[j].innerHTML = unit[j]; drawer += cid[j][1];}
if (i == 1) {elements[18 + j].innerHTML = Math.floor(cid[j][1] / multiplier[j]);}
if (i == 2) {elements[9 + j].innerHTML = "$ " + (cid[j][1] * 1).toFixed(2);}
}
}
itemPrice.value = price;
}
function moneyIn(cashDistributor) {
for (let i = 8; i >-1;i--) {
while (cashDistributor >= multiplier[i]) {
cid[i][1] = cid[i][1] + multiplier[i];
cashDistributor -= multiplier[i];
}
}
populator();
}
function noTrailingZeros(numb) {
if (Math.floor(numb) !== numb) {
if (numb.toFixed(2) % 1 !== 0) {
let deciminus = ((numb - Math.floor(numb)) * 100).toFixed(2);
numb = Math.floor(numb) + (deciminus / 100);
if(deciminus < 100) {
return numb;
} else {
return numb.toFixed(2);
}
} else {
return numb.toString();
}
} else {
return numb.toString();
}
}
function dividender (changeOfType, con) {
for (let i = 8; i > -1; i--) {
if (i != 0){
console.log(changeOfType);
numberOfUnits = Math.floor(Math.min(changeOfType / multiplier[i], cid[i][1] / multiplier[i]));
} else {
numberOfUnits = Math.min(changeOfType / multiplier[i], cid[i][1] / multiplier[i]);
}
unit[i] = numberOfUnits;
if (numberOfUnits > 0) {
changeOfType -= (numberOfUnits * multiplier[i]);
drawer -= cid[i][1];
cid[i][1] -= (numberOfUnits * multiplier[i]);
let hold = noTrailingZeros(numberOfUnits * multiplier[i]);
str += (cid[i][0] + ": $" + hold + " ");
}
}
if (changeOfType > 0 || changeOfType > drawer) {
cond = 2;
} else cond = con;
}
function update () {
if(cond < 4) {
moneyIn(cash);
denominant.style.display = "inline";
denominant.style.border = "1px solid #ad2";
denominant.style.width = "346px";
denominant.style.overflow = "hidden";
}
if (cond < 2) {changeDue.innerHTML = messages[cond] + " " + str;}
if (cond === 2) {changeDue.innerHTML = messages[cond];}
if (cond === 3) {changeDue.innerHTML = "No change due - customer paid with exact cash";}
if (cond === 4) {changeDue.innerHTML = messages[2] + " " + str;}
if (cond === 5) {changeDue.innerHTML = "Please enter a valid number";}
if (cond === 6) {alert("Customer does not have enough money to purchase the item");}
}
purchaseBtn.addEventListener("click", () => {
str = "";
unit = Int32Array.from([0, 0, 0, 0, 0, 0, 0, 0, 0]);
cash = parseFloat((numIn.value == undefined ? 0 : numIn.value.trim()))
change = (cash - price);
let set = false;
if (!cash && !set) {
set = true;
cond = 5;//no value entered
}
if (cash < price && !set) {
set = true;
cond = 6;//customer doesn't have enough money
}
if (change > drawer && !set) {
set = true;
cond = 4; //insufficient funds in drawer
}
if (cash === price && !set) {
set = true;
cond = 3;//paid with exact amount
}
if (change === drawer && !set) {
set = true;
cond = 1;//register closed with a ballance of 0
dividender(change, 1);
}
if (change < drawer && !set) {//Normal transaction
set = true;
dividender(change, 0);
}
update(cond);
populator();
});
clearBtn.addEventListener("click", () => {
changeDue.innerHTML = "";
itemPrice.value = price;
cash = 0;
numIn.value = "";
str = "";
unit = Int32Array.from([0, 0, 0, 0, 0, 0, 0, 0, 0]);
numberOfUnits = 0;
denominant.style.border = "none";
denominant.style.display = "none";
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Build a Cash Register Project - Build a Cash Register