Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let fruit = input.shift();
- let day = input.shift();
- let count = Number(input.shift());
- let weekDay = false;
- let weekEnd = false;
- let isError
- let price = Number;
- if (day === 'monday' || day === 'tuesday' || day === 'wednesday' || day === 'thursday' || day === 'friday') {
- weekDay = true;
- }
- if (day === 'saturday' || day === 'sunday') {
- weekEnd = true;
- }
- if (weekEnd === false && weekDay === false) {
- isError = true;
- }
- switch (fruit) {
- case 'banana':
- if (weekDay === true) {
- price = 2.50;
- console.log((price * count).toFixed(2))
- } if (weekEnd === true) {
- price = 2.70
- console.log((price * count).toFixed(2))
- }
- break;
- case 'apple':
- if (weekDay === true) {
- price = 1.20
- console.log((price * count).toFixed(2))
- } if (weekEnd === true) {
- price = 1.25
- console.log((price * count).toFixed(2))
- }
- break;
- case 'orange':
- if (weekDay === true) {
- price = 0.85
- console.log((price * count).toFixed(2))
- } if (weekEnd === true) {
- price = 0.90
- console.log((price * count).toFixed(2))
- }
- break;
- case 'grapefruit':
- if (weekDay === true) {
- price = 1.45
- console.log((price * count).toFixed(2))
- } if (weekEnd === true) {
- price = 1.60
- console.log((price * count).toFixed(2))
- }
- break;
- case 'kiwi':
- if (weekDay === true) {
- price = 2.70
- console.log((price * count).toFixed(2))
- } if (weekEnd === true) {
- price = 3.00
- console.log((price * count).toFixed(2))
- }
- break;
- case 'grape':
- if (weekDay === true) {
- price = 3.85
- console.log((price * count).toFixed(2))
- } if (weekEnd === true) {
- price = 4.20
- console.log((price * count).toFixed(2))
- }
- break;
- case 'pineapple':
- if (weekDay === true) {
- price = 5.50
- console.log((price * count).toFixed(2))
- } if (weekEnd === true) {
- price = 5.60
- console.log((price * count).toFixed(2))
- }
- break;
- }
- }
- solve ([ 'orange', 'sunday', '3'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement