Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.9 kB
2
Indexable
Never
function fruitshop(input) {
 
    let fruitName = input[0];
    let dayOfWeek = input[1];
    let quantity = Number(input[2]);
    let error = false;
    let price = 0;
 
 
 
    switch (dayOfWeek) {
 
        case 'Monday':
        case 'Tuesday':
        case 'Wednesday':
        case 'Thursday':
        case 'Friday':
            if (fruitName === 'banana') {
                price = quantity * 2.5;
            } else if (fruitName === 'apple') {
                price = quantity * 1.20;
            } else if (fruitName === 'orange') {
                price = quantity * 0.85;
            } else if (fruitName === 'grapefruit') {
                price = quantity * 1.45;
            } else if (fruitName === 'kiwi') {
                price = quantity * 2.70;
            } else if (fruitName === 'pineapple') {
                price = quantity * 5.5;
            } else if (fruitName === 'grapes') {
                price = quantity * 3.85;
            } else error = true; break;
        case 'Saturday':
        case 'Sunday':
            if (fruitName === 'banana') {
                price = quantity * 2.7;
            } else if (fruitName === 'apple') {
                price = quantity * 1.25;
            } else if (fruitName === 'orange') {
                price = quantity * 0.90;
            } else if (fruitName === 'grapefruit') {
                price = quantity * 1.60;
            } else if (fruitName === 'kiwi') {
                price = quantity * 3.00;
            } else if (fruitName === 'pineapple') {
                price = quantity * 5.6;
            } else if (fruitName === 'grapes') {
                price = quantity * 4.20;
            }else error = true; break;
            
        default: error = true; break;
    } 
 if (error != true){
    console.log(price.toFixed(2));
 }
 else{
    console.log('error');
 }
   }
Leave a Comment