Tell us what’s happening:
im done with this project but im failing 3 tests although the output is just as wanted im failing tests 13,18 and 19
Your code so far
<!-- file: index.html -->
<html>
<body>
<p>enter input</p>
<input id="cash">
<div id="change-due"></div>
<button id="purchase-btn">purchase</button>
<script src="script.js"></script>
</body>
</html>
/* file: script.js */
let price = 3.26;
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 btn=document.getElementById("purchase-btn")
const changedue=document.getElementById("change-due")
let num=0
let outp=""
let outp2=""
let def=[0.01,0.05,0.1,0.25,1,5,10,20,100]
let def2=[]
let check=false
let control=0;
let pres=false
//ceil
for(let i=0;i<cid.length;i++){
def2.push([def[i],Math.ceil(cid[i][1]/def[i])])
}
btn.addEventListener("click",calc)
function calc(){
let returns=parseFloat(cash.value)-price
if(parseFloat(cash.value)<price){
alert("Customer does not have enough money to purchase the item")
return
}
else if(parseFloat(cash.value)===price){
changedue.innerHTML="No change due - customer paid with exact cash"
return
}
else{ for(let i=def2.length-1;i>=0;i--){
num=0
check=false
while(def2[i][0]<returns&&def2[i][1]!=0&&parseFloat((def2[i][0]+control).toFixed(2))<=returns){
control+=def2[i][0];
control=parseFloat(control.toFixed(2))
num+=def2[i][0]
def2[i][1]--;
check=true
}
if(check){
outp2+=cid[i][0]+": $"+num+" "
}
if(control===returns){break;}
if(def2[i][1]!==0){
pres=true
}
}
}
if(control!=returns){
outp="Status: INSUFFICIENT_FUNDS"
}
else if(pres){
outp="Status: OPEN "+outp2
}
else{
outp="Status: CLOSED "+outp2
} changedue.innerHTML=outp
}
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Challenge Information:
Build a Cash Register Project - Build a Cash Register