Tell us what’s happening:
Hello everybody,
I need a little help because I feel a little bit lost…
My code seems working on my different browser’s consoles (chrome, safari, firefox). It returns exactly what the tests want but when I press “run the tests” on freeCodeCamp everything is wrong except the first (“should return an object.”)…
If somebody can explain to me what’s wrong, I would be very thankful !!!
(Sorry for my English)
Brice
Your code so far
var argent = [
{name: "PENNY", value: 0.01},
{name: "NICKEL", value: 0.05},
{name: "DIME", value: 0.1},
{name: "QUARTER", value: 0.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) {
var monnaie = {
statut: "",
change: []
};
var moneyBack = cash - price;
let cashInDrawer = 0;
let rest = 0;
console.log(moneyBack);
for(var i=0; i<cid.length; i++) {
cashInDrawer += cid[i][1];
}
let variable = moneyBack;
if (cashInDrawer < moneyBack) {
monnaie.statut = "INSUFFICIENT_FUNDS";
monnaie.change = [];
} else if(cashInDrawer == moneyBack) {
monnaie.statut = "CLOSED";
} else if(cashInDrawer > moneyBack) {
monnaie.statut = "OPEN";
for(var j=cid.length-1; j>=0; j--) {
if(cid[j][1]>0) {
if((moneyBack/argent[j].value)>1){
let max = cid[j][1]/argent[j].value;
var n=0;
for(var k=1; k<=max; k++) {
if((variable-argent[j].value)>=0){
n++;
variable -= argent[j].value;
variable = Math.round(variable*100)/100;
}
}
if((n*argent[j].value)>0){
monnaie.change.push([cid[j][0], (n*argent[j].value)]);
}
}
}
}
}
return(monnaie);
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register/