This code must give the output of the total cash , but rather gives wrong output? Can anybody please tell me what is wrong in it.
var cashRegister = {
total:0,
add: function(itemCost)
{
this.total += itemCost;
}
};
var i;
for (i=0; i<4; i++)
{
var a = prompt("Cost");
cashRegister.add(a);
}
//call the add method for our items
//Show the total bill
console.log('Your bill is '+cashRegister.total);