POS cashier version: v1
- Practice Tasking;
- Practice JS collection operation;
A cash register (POS) system is used in the store for settlement of the store. This cashier will settle and print receipts at the time of settlement based on the item(Item) in the customers’ cart (Cart) and the ongoing promotion(Promotion) of the store.
It is known that the store is offering "buy two and get one free" for some products. One product has only one kind of preferential activity at the same time.
We need to implement a function called printReceipt
, which can input the data of the specified format as a parameter and then output the text of the receipt in the browser console.
Input format (example):
[
'ITEM000001',
'ITEM000001',
'ITEM000001',
'ITEM000001',
'ITEM000001',
'ITEM000003-2',
'ITEM000005',
'ITEM000005',
'ITEM000005'
]
For 'ITEM000003-2', what before""-"" is the standard barcode and what after ""-"" is the number, which may be a decimal. When we buy an item that needs to be weighed, such a tag is generated by a weighing machine, and the cashier is responsible for identifying the receipt.
Contents of the List (example):
***<store earning no money>Receipt ***
Name: Coca-Cola, Quantity: 3 bottles, Unit price: 3.00 (yuan), Subtotal: 6.00 (yuan)
Name: Badminton, Quantity: 5, Unit price: 1.00 (yuan), Subtotal: 4.00 (yuan)
Name: Apple, Quantity: 2 kg, Unit price: 5.50 (yuan), Subtotal: 11.00 (yuan)
----------------------
Total: 21.00 (yuan)
Saving: 4.00 (yuan)
**********************
- According to the test case in
test/main-test.js
, write the implementation code in themain/main.js
file and make sure to pass the test; - Please complete the homework with the minimum number of lines of code while ensuring the readability of the code;
- Please submit the completed homework to your GitHub repository;
- Please maintain good habits of code committing(Commit).
-
You can use the method
loadAllItems()
to get all the items. -
Use the method
loadPromotions()
to get all the promotion information.