Cash Register Project strange output

Cash Register Project strange output
0

#1

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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register


#2

#3

Yeah Im’ going to have to do that… now I’m having another “similar problem” where a condition of a sum of 2 values that equal 0.25 is greater than 0.5, and its actually being true…


#4

Ok what am I supposed to do when 2.05 * 100.0 equals 204??


#5

Depending on where/how you multiply by 100, you can avoid this situation, but otherwise Math.round().