Building a cash register 2


#1


building a cash register 2


when i run my code this is the output "Your bill is 7.5600000000000005"


var cashRegister = {
    total:0,
    add: function(itemCost){
        this.total += itemCost;
    }
};


//call the add method for our items
cashRegister.add(0.89);
cashRegister.add(1.23);
cashRegister.add(4.99);
cashRegister.add(0.45);
//Show the total bill
console.log('Your bill is '+cashRegister.total);


#2

Try to use .toFixed() method:

console.log('Your bill is '+cashRegister.total.toFixed(2));

UPDATED. @arrayjumper38522, thank you for your correction.


#3

Is the exercise 2 manually add it up?

If so, eggs price are 0.98
cashRegister.add(0.98);

You are using 0.89


#4

It's .toFixed(2):

not .toFix(2);

:slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.