Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

Axiomatik avatar Axiomatik 2422 Точки

Demo Code (100%), ;-)

function solve(input) {
    let priceWithoutTaxes = 0
    let type = input.pop().toLowerCase();
    let taxes = 0
    let totalPrice = 0

    for (price of input) {
        const currentPrice = Number(price);

        // If a given price is not a positive number, you should print
        // "Invalid price!" on the console and continue with the next price.
        if (price > 0) {
            priceWithoutTaxes += currentPrice
        } else {
            console.log("Invalid price!")
            continue;
        }
    }

    // If the total price is equal to zero, you should print "Invalid order!" on the console.
    if (priceWithoutTaxes === 0) {
        return console.log("Invalid order!")
    }

    // The taxes are 20% of each part's price you receive. 
    taxes = priceWithoutTaxes * 0.2
    totalPrice = taxes + priceWithoutTaxes

    // If the customer is special, he has a 10% discount on the total price with taxes.
    if (type === "special") {
        totalPrice = totalPrice - (totalPrice * 0.1)
    }

    console.log(`Congratulations you've just bought a new computer!`)
    console.log(`Price without taxes: ${priceWithoutTaxes.toFixed(2)}$`)
    console.log(`Taxes: ${taxes.toFixed(2)}$`)
    console.log("-----------")
    console.log(`Total price: ${totalPrice.toFixed(2)}$`)
}

 

0
Ivelinka avatar Ivelinka 24 Точки

Благодаря,

но аз исках да видя къде е грешката в моя код :)

0
Axiomatik avatar Axiomatik 2422 Точки
function solve2(input) {
    let index = 0;
    let command = input[index];
    index++;

    let priceNoTax = 0;
    let finalPrice = 0;
    let tax = 0;

    while (command !== "special" && command !== "regular") {
        let currPrice = Number(command);

        if (currPrice <= 0) {
            console.log("Invalid price!");
        } else {
            priceNoTax += currPrice;
        }

        command = input[index];
        index++;
    }

    tax = (priceNoTax * 1.20) - priceNoTax;
    finalPrice = priceNoTax + tax;

    if (finalPrice === 0) {
        return console.log("Invalid order!");
    }

    if (command === "special") {
        finalPrice *= 0.90;
    } else {
        finalPrice = finalPrice
    }

    console.log("Congratulations you've just bought a new computer!");
    console.log(`Price without taxes: ${priceNoTax.toFixed(2)}$`)
    console.log(`Taxes: ${tax.toFixed(2)}$`)
    console.log("-----------")
    console.log(`Total price: ${finalPrice.toFixed(2)}$`)
}

 

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.