Having some problems with Cash Register getting the sum of money in cid

Tell us what’s happening:
I’ve converted the cid into an object called stuff then used the switch statement to sum the money of stuff, but it returns money = 0.
Any help would be appreciated.

Your code so far


function checkCashRegister(price, cash, cid) {
var change;
function toObject(arr) {
var rv = {};
for (let i = 0; i < cid.length; i++) {
  rv[i] = arr[i][1];
}
return rv;
}
//SIZE OF THE OBJECT
let stuff = toObject(cid);
Object.size = function(obj) {
  var size = 0, key;
  for (key in obj) {
      if (obj.hasOwnProperty(key)) size++;
  }
  return size;
};

// Get the size of an object
var size = Object.size(stuff);
let money = 0;
for (let i = 0; i < size; i++) {
switch(i) 
{
case "0": money = money + stuff[i]*0.01;break;
case "1": money = money + stuff[i]*0.05;break;
case "2": money = money + stuff[i]*0.1;break;
case "3": money = money + stuff[i]*0.25;break;
case "4": money = money + stuff[i]*1;break;
case "5":  money = money + stuff[i]*10;break;
case "6": money = money + stuff[i]*0.05;break;
case "7": money = money + stuff[i]*100;break;
}
}
return money;
}

let a = 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]]);
console.log(a);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36.

Challenge: Cash Register

Link to the challenge:

there are a few logic issues, but to answer specifically to your question, this part of your code doesn’t work because the i is a number, so none of the cases in the switch statement get executed

1 Like

Oh man, I forgot about that part. Thank you for the feedback.