Tell us what’s happening:
Hey, so does anyone have any idea why this would output this:
When dividing 2.05 by 0.05 it suddenly freaks out…
Thanks in advance for any help given!
Your code so far
function checkCashRegister(price, cash, cid) {
var change = cash - price;
let arr = [];
let sum = 0;
for (let i in cid) sum += cid[i][1];
if (sum < change) return {status: "INSUFFICIENT_FUNDS", change: []};
else if (sum == change) return {status: "CLOSED", change: cid};
else{
let obj = {
"PENNY": 0.01,
"NICKEL": 0.05,
"DIME": 0.1,
"QUARTER": 0.25,
"ONE": 1,
"FIVE": 5,
"TEN": 10,
"TWENTY": 20,
"ONE HUNDRED": 100}
for (let item in cid){
arr.push([ obj[cid[item][0]] , cid[item][1] / obj[cid[item][0]] ]);
console.log(arr);
}
}
// Here is your change, ma'am.
return {status: "OPEN", change: arr};
}
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 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0
.
Link to the challenge: