Cash register not passing but answers are right

Why am I not passing the test when my answers are right?

   **Your code so far**
let myArr1 = 
 [{name:"PENNY", value:.01},
  {name:"NICKEL", value:.05},
  {name:"DIME", value:.1},
  {name:"QUARTER", value:.25}, 
  {name:"ONE", value:1},
  {name:"FIVE", value:5},
  {name:"TEN", value: 10},
  {name:"TWENTY", value: 20},
  {name:"ONE HUNDRED", value: 100}]




function checkCashRegister(price, cash, cid) { 
 

let myArr2 = myArr1.reverse()
let output = {status: null, change: []}
 let change = cash  - price
 
let register =cid.reduce (
 function(account,currency){ 
account.total += currency[1]
account[currency[0]] = currency[1]

 return account
 },
 {total: 0}
 )
 


if(register.total === change){
   output.status = "CLOSED"
   output.change =cid
   return output
}
if(register.total < change){
 output.status = "INSUFFICIENT_FUNDS"
 return output
}

let myValue = myArr2.reduce(function(account,currency){
 let num =0
 while(register[currency.name] > 0 && change >= currency.value ){
   change -= currency.value
   register[currency.name] -= currency.value
   num += currency.value
   

change = Math.round(change * 100) /100

 }
 if(num > 0){
   account.push([currency.name, num])
 }

 return account

},[]) 
if (myValue.length < 1 || change> 0) {
 output.status = "INSUFFICIENT_FUNDS"
 return output
}
output.status = "OPEN"
output.change = myValue
return output
}
  

console.log(checkCashRegister(3.26, 100, [["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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Cash Register

Link to the challenge:

Having a global value you change during the function execution is really bad practice, you get unexpected results

what global value? the let myArr?

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