POS Cash Register Version:v1
- The basic syntax familiar with JavaScript;
- Familiar with JavaScript basic logic statements and keywords;
The store will use the cash register (POS) systems when shopping settlement, This cashier will settle and print the receipt (Receipt) according to the item in the customer's shopping cart (Cart) And ongoing promotions at the store(Promotion)at the time of settlement .
The store is offering a "buy two get one free" offer for some products. One item has one and only one kind of promotion at the same time.
We need to implement a function called printReceipt
, This function can input 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'
]
Which for 'ITEM000003-2',Before "-" is the standard barcode, After the "-" is the quantity, The number may be a decimal. When we buy items that we need to weigh,These tags (Tag) will be generated by the weighing machine, The cash register is responsible for identifying the receipt。
List Contents(example):
***<store earning no money>Receipt ***
Name:Coca-Cola,Quantity:3 bottles,Unit:3.00(yuan),Subtotal:6.00(yuan)
Name:Badminton,Quantity:5 a,Unit:1.00(yuan),Subtotal:4.00(yuan)
Name:Apple,Quantity:2 pounds,Unit:5.50(yuan),Subtotal:11.00(yuan)
----------------------
Total:21.00(yuan)
Discounted prices: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 the test passes; - Please complete the assignment with the least number of lines of code as much as possible while ensuring the readability of the code;
- Run the
run.html
file below the file to make the test pass;
- According to the test case in
-
Use the
loadAllItems()
method to get all the items, This method returns the result as an array containing the item objects.(example):[ item1, item2, item3, ..., itemN ]
-
The structure of each commodity object is as follows(example):
{ barcode: 'ITEM000000', name: 'Coca-Cola', unit: 'bottle', price: 3.00 }
-
Use the
loadPromotions()
method to get all the promotion information, This method returns the result as an array containing the promotion information object (example):[ { type: 'BUY_TWO_GET_ONE_FREE', barcodes: [ 'ITEM000000', 'ITEM000001' ] }, { type: 'OTHER_PROMOTION', barcodes: [ 'ITEM000003', 'ITEM000004' ] } ]
-
You should learn and be good at using the Console feature in the developer tools that come with the popular browsers.