Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fruitShop(input) {
- let product = input.shift();
- let day = input.shift();
- let qty = Number(input.shift());
- let qtyPrice = 0;
- if (day === "Monday" || day === "Tuesday" || day === "Wednesday" ||
- day === "Thursday" || day === "Friday") {
- switch(product) {
- case "banana":
- qtyPrice = qty * 2.50;
- break;
- case "apple":
- qtyPrice = qty * 1.20;
- break;
- case "orange":
- qtyPrice = qty * 0.85;
- break;
- case "grapefruit":
- qtyPrice = qty * 1.45;
- break;
- case "kiwi":
- qtyPrice = qty * 2.70;
- break;
- case "pineapple":
- qtyPrice = qty * 5.50;
- break;
- case "grapes":
- qtyPrice = qty * 3.85;
- break;
- default :
- console.log("error");
- break;
- }
- } else if (day === "Saturday" || day === "Sunday") {
- switch(product) {
- case "banana":
- qtyPrice = qty * 2.70;
- break;
- case "apple":
- qtyPrice = qty * 1.25;
- break;
- case "orange":
- qtyPrice = qty * 0.90;
- break;
- case "grapefruit":
- qtyPrice = qty * 1.60;
- break;
- case "kiwi":
- qtyPrice = qty * 3.00;
- break;
- case "pineapple":
- qtyPrice = qty * 5.60;
- break;
- case "grapes":
- qtyPrice = qty * 4.20;
- break;
- default :
- console.log("error");
- break;
- }
- }else {
- console.log("error");
- }
- if (qtyPrice !== 0) {
- console.log(qtyPrice.toFixed(2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement