JavaScript Algorithms and Data Structures Projects - Cash Register

Tell us what’s happening: is there anything that i have missed bec its not working

Describe your issue in detail here.

Your code so far

function checkCashRegister(price, cash, cid) {
 let change ; /*[
    ["Penny" ,0.01],
    ["Nickel" ,0.05],
    ["Dime" , 0.1 ],
    ["Quarter",0.25],
    ["Dollar",1],
    ["Five Dollars",5 ],
    ["Ten Dollars"	,10] ,
    ["Twenty Dollars"	,20 ],
    ["One-hundred Dollars",100] 
  ]*/

let cidTotal = 0;
for (let elem of cid){
     console.log(cidTotal += elem[1])
}
let rev = cid.reverse()
 let revTotal = 0
for (let elem of rev){
console.log(revTotal += elem[1])



const changedue = cash - price
const chnn = cidTotal - changedue;
const fnn = revTotal - changedue;
console.log(fnn)

  let yeschange= {status: "OPEN", change: [fnn]}
  let nomoney= {status: "INSUFFICIENT_FUNDS", change: []}
  let nochange={status: "CLOSED", change: cid}




if (cidTotal < changedue || changedue < chnn){
  return nomoney
} else if(cidTotal === changedue){ return nochange
}else if(cidTotal => changedue){
  return yeschange;
}


}}
console.log(checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]));

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 17_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3.1 Mobile/15E148 Safari/604.1

Challenge Information:

JavaScript Algorithms and Data Structures Projects - Cash Register

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

from the numbers I see in the console, it looks like you are having issues with floating point errors, I suggest this video:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.