This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by SBX6
over 10 years

Please help me in this : Did you scan four of each item?

Here is a code: Where is my mistake?

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',1);
cashRegister.scan('milk',1);
cashRegister.scan('magazine',1);
cashRegister.scan('chocolate',4);
//Show the total bill
console.log('Your bill is '+cashRegister.total);

Answer 52763367f10c606f04002ed2

0 votes

Permalink

That’s my question too. Did you scan each item four times? Examine line 16 to line 18 and see what needs to be changed.

points
Submitted by Aden Fission
over 10 years

10 comments

SBX6 over 10 years

I’ve tried everything but the error is the same!! I don’t know …. !

Aden Fission over 10 years

I will read our line 16 to line 18 for you and see if that helps. “Scan an egg into the cash register. Scan a milk into the cash register. Scan a magazine into the cash register.” The instructions want you to scan four of each. The second argument in the function call denotes the quantity of an item to scan.

SBX6 over 10 years

Yes the instructions want to scan four of each, this is Okay, but again is the same error. in the instructions , respectively in “hint” writes: “”Unit Test Our test expects the second parameter to be quantity as the examples above.””.This means that the second parameter should be as the examples above? I’m not understanding this because no examples to set “quantity”; Thankkss a lot!

SBX6 over 10 years

Did you have completed this?

Aden Fission over 10 years

Yes, I have completed this. Let’s talk about something else before I decide on the best track to explain this. What do you think the scan method in the cashregister object does? Don’t just say ‘it scans an item’. Explain HOW it works.

SBX6 over 10 years

the scan method is a method which takes two parameters (item and quantity), in our case when we have .ex. eggs or milk or something else…example in case “eggs”: this.add(0.98 * quantity), call add method which gives itemCost and quantity the return total = total + itemcost. I do not know if I’ve been clear!!!

SBX6 over 10 years

I solved that :D
Thanks.

Aden Fission over 10 years

Well, you tried! :D Here’s a better explanation: the scan method accepts two values: an item name, and the number of that item to scan (the ‘quantity’). It then adds the cost of that item to the total as many times as the number of that item to scan by adding the product of the item’s cost and quantity to the total. The exercise wants you to scan FOUR eggs, while the current code scans ONE egg. This is because on line 16, you are saying “scan an egg 1 time” when you should be saying “scan an egg, 4 times”. That would mean that you would change the second value passed into the function from 1 to 4. Got it?

Aden Fission over 10 years

Lol, you ninja’d me by 3 minutes. Cheers! ^___^

SBX6 over 10 years

Yes i solved this problem , thanks.