Push method turns empty array

Tell us what’s happening:
Hello,
I am trying to add an element to the array that is located within the object, using the push method. It turns empty array. What did I do wrong?
Many thanks.

Your code so far
var output={status: null, change: }
output.status=‘OPEN’
output[‘change’].push[100]


function checkCashRegister(price, cash, cid) {
 var output={status:null,change:[]}
 output.status='OPEN'
//test if an element will be added to the array
 output['change'].push[100]
 console.log(output)


 //calculate and round change
 var change=(cash-price).toFixed(2)

//convert array into object. Calculate total amount of money in the //register
var register=cid.reduce(
 function(obj,arr){
 obj.sum += arr[1]
 obj[arr[0]]=arr[1];
return obj
},
{sum: 0})

//case surplus in the register
if(register.sum>=change){
output.status='OPEN'
while (change>=100 && register['ONE HUNDRED']>=100){
 
 change -= 100;
 register['ONE HUNDRED'] -= 100
 output['change'].push[100]
 
}



while (change>=20 && register['TWENTY']>=20){
 change -= 20;
 register['TWENTY'] -= 20
}

while (change>=10 && register['TEN']>=10){
 change -= 10;
 register['TEN'] -= 10
}
while (change>=5 && register['FIVE']>=5){
 change -= 5;
 register['FIVE'] -= 5
}
while (change>=1 && register['ONE']>=1){
 change -= 1;
 register['ONE'] -= 1
}
while (change>=0.25 && register['QUARTER']>=0.25){
 change -= 0.25;
 register['QUARTER'] -= 0.25
}
while (change>=0.1 && register['DIME']>=0.1){
 change -= 0.1;
 register['DIME'] -= 0.1
}
while (change>=0.05 && register['NICKEL']>=0.05){
 change -= 0.05;
 register['NICKEL'] -= 0.05
}
while (change>=0.05 && register['NICKEL']>=0.05){
 change -= 0.05;
 register['NICKEL'] -= 0.05
}
while (change>=0.001 && register['PENNY']>=0.1){
 change -= 0.01;
 register['PENNY'] -= 0.01
}
change = Math.round(change * 100) / 100;
}
//end case surplus in the register


//console.log('stotka ' +register['ONE HUNDRED'])
//console.log('dvadesetice ' +register['TWENTY'])
//console.log('desetice ' +register['TEN'])
//console.log('petice ' +register['FIVE'])
//console.log('jedinice ' +register['ONE'])
//console.log('kvarteri ' +register['QUARTER'])
//console.log('dajmovi ' +register['DIME'])
//console.log('niklovi ' +register['NICKEL'])
//console.log('peni ' +register['PENNY'])

//console.log('kusur ' +change)




}


checkCashRegister(335.0157, 570.49345
, [["PENNY", 1.01], ["NICKEL", 2], ["DIME", 3], ["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 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.

Challenge: Cash Register

Link to the challenge:

Push is a function. Look carefully at the push declaration: the syntax is wrong.

1 Like

You used brackets instead of parentheses ( ), remember this is a function.

1 Like