Code works but I can't Submit as it returns an error though I have the proper output


#1


Building a cash Register


var cashRegister = {
    total:0,
    add: function(itemCost){
        this.total += (itemCost);
    },
    scan: function(item,quantity) {
        switch (item) {
        case "eggs": this.add(0.98 * quantity); break;
        case "milk": this.add(1.23 * quantity); break;
        case "magazine": this.add(4.99 * quantity); break;
        case "chocolate": this.add(0.45 * quantity); break;
        }
    }
};

// scan each item 4 times
cashRegister.scan("magazine",4);
cashRegister.scan("eggs",4);
cashRegister.scan("milk",4);
cashRegister.scan("chocolate",4);


//Show the total bill
console.log('Your bill is '+cashRegister.total);


#3

var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
},
scan: function(item,quantity) {
switch (item) {
case "eggs": this.add(0.98 * quantity); break;
case "milk": this.add(1.23 * quantity); break;
case "magazine": this.add(4.99 * quantity); break;
case "chocolate": this.add(0.45 * quantity); break;
}
}
};

// scan each item 4 times
cashRegister.scan("eggs",4);
cashRegister.scan("milk",4);
cashRegister.scan("magazine",4);
cashRegister.scan("chocolate",4);

//Show the total bill
console.log('Your bill is '+cashRegister.total);


#4

I am also getting an error message that says " It doesn't seem like your 'quantity' actually works!" even though I am getting the correct output ("Your bill is 30.6"). Have you figured out what was causing it?

Here is my code (copy-pasting got rid of formatting, sorry):

var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
},
scan: function(quantity, item) {
switch (item) {
case "eggs": this.add(0.98* quantity); break;
case "milk": this.add(1.23*quantity); break;
case "magazine": this.add(4.99*quantity); break;
case "chocolate": this.add(0.45*quantity); break;
}
}
};

cashRegister.scan(4, "eggs");
cashRegister.scan(4, "milk");
cashRegister.scan(4, "magazine");
cashRegister.scan(4, "chocolate");

//Show the total bill
console.log('Your bill is '+cashRegister.total);


#5

AHHHRRRG! Even though it wasn't at all mentioned in the instructions, they needed you to put the quantity variable SECOND in the function. It made more sense to me to enter (4, "eggs") instead of ("eggs", 4), so I did it the other way.


#6

I scanned each item four times with quantity value as 1 and that test case passed. I have no idea why that happened. Some bug probably.


#7

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