无论输入如何,它总是使用A或参数输出

时间:2017-03-21 23:42:22

标签: javascript switch-statement

如何让它对“A' A'以外的输入作出相应的回应?和' a'?注意:没有.toUpperCase()或类似语句。它必须能够处理' A'并且' a'。最好保持开关声明

function Ticket() {
    var ticketType = prompt('What type of ticket do you want');
    var ticketQty = parseInt(prompt('How many tickets do you want'));

    document.write('Ticket type is: ' + ticketType + '<br />');
    document.write('Ticket quantity is: ' + ticketQty + '<br />');

    ticketPrice = 0;

    switch(ticketType) {
        case 'A':
            var ticketPrice = 100;
            break;
        case 'a':
            var ticketPrice = 100;
            break;
        default:
            ticketTypePrice();
    }

    function ticketTypePrice () {
         if (ticketType == 'B') {
            var ticketPrice = 75;
        } else if (ticketType == 'C') {
            var ticketPrice = 50;
        } else {
            document.write('Invalid Ticket Type' + '<br />');
        }
    }

    if (ticketQty < 1 || ticketQty > 100) {
        document.write('Invalid Quantity' + '<br />');
    }

    if (ticketPrice > 0 && ticketQty > 0 && ticketQty < 100) {
        totalticketPrice = (ticketPrice * ticketQty);
        document.write('Ticket Payment Required: ' + totalticketPrice);
    }
}

Ticket();

0 个答案:

没有答案