@JyriG

Рассчитать скидки?

Как рассчитать скидку в единицах и процентах и указать изначальную цену? sale1, sale2, sale3 & sale4 - это те значения, которые я хочу включить в расчеты.

КОД:
function getObj_TypePrice() {
            var obj_type = new Array();
            obj_type["sisavisualisoinnit"] = 0;
            obj_type["ulkovisualisoinnit"] = 0;
            obj_type["molemmat"] = 350;
           var CakeCountPrice = 0;
            //Get a reference to the cake the user Chooses name=rakennus_tyyppi":
            var rakennus_tyyppi = theForm.elements["rakennus_tyyppi"];
            //Here since there are 4 radio buttons rakennus_tyyppi.length = 4
            //We loop through each radio buttons
            for (var i = 0; i < rakennus_tyyppi.length; i++) {
                //if the radio button is checked
                if (rakennus_tyyppi[i].checked) {
                    //we set CakeCountPrice to the value of the selected radio button
                    //i.e. if the user choose the 8" cake we set it to 25
                    //by using the obj_type array
                    //We get the selected Items value
                    //For example obj_type["Round8".value]"
                    CakeCountPrice = obj_type[rakennus_tyyppi[i].value];
                    //If we get a match then we break out of this loop
                    //No reason to continue if we get a match
                    break;
                }
            }
            //We return the CakeCountPrice
            return CakeCountPrice;
        }
            var sale1 = 0.975;
            var sale2 = 0.95;
            var sale3 = 0.925;
            var sale4 = 0.9;
        function getObj_CountPrice() { 
            
                var objects_count = new Array();
                    objects_count["obj_count-1"] = 350;
                    objects_count["obj_count-2"] = 350 * 2 * sale1;
                    objects_count["obj_count-3"] = 350 * 3 * sale2;
                    objects_count["obj_count-4"] = 350 * 4 * sale3;
                    objects_count["obj_count-5"] = 350 * 5 * sale4;       
                var Obj_CountPrice = 0;

                //Get a reference to the form id="cakeform"
                var obj_count = theForm.elements["obj_count"];
                //Here since there are 4 radio buttons rakennus_tyyppi.length = 4
                //We loop through each radio buttons
                Obj_CountPrice = objects_count[obj_count.value];
                for (var i = 0; i < obj_count.length; i++) {
                    //if the radio button is checked
                    if (obj_count[i].checked) {
                        //we set CakeCountPrice to the value of the selected radio button
                        //i.e. if the user choose the 8" cake we set it to 25
                        //by using the objects_count array
                        //We get the selected Items value
                        //For example objects_count["Round8".value]"
                        Obj_CountPrice = objects_count[obj_count[i].value];
                        //If we get a match then we break out of this loop
                        //No reason to continue if we get a match
                        break;

                    }
                }
                //We return the Obj_CountPrice
                return Obj_CountPrice;
            }

            function getObj_CountPrice2() { 
                var objects_count2 = new Array();
                    objects_count2["obj2_count-1"] = 350;
                    objects_count2["obj2_count-2"] = 350 * 2 * sale1;
                    objects_count2["obj2_count-3"] = 350 * 3 * sale2;
                    objects_count2["obj2_count-4"] = 350 * 4 * sale3;
                    objects_count2["obj2_count-5"] = 350 * 5 * sale4;       
                var Obj_CountPrice2 = 0;

                //Get a reference to the form id="cakeform"
                var obj2_count = theForm.elements["obj2_count"];
                //Here since there are 4 radio buttons rakennus_tyyppi.length = 4
                //We loop through each radio buttons
                Obj_CountPrice = objects_count2[obj2_count.value];


                for (var i = 0; i < obj2_count.length; i++) {
                    //if the radio button is checked
                    if (obj2_count[i].checked) {
                        //we set CakeCountPrice to the value of the selected radio button
                        //i.e. if the user choose the 8" cake we set it to 25
                        //by using the objects_count array
                        //We get the selected Items value
                        //For example objects_count["Round8".value]"
                        Obj_CountPrice2 = objects_count2[obj2_count[i].value];
                        //If we get a match then we break out of this loop
                        //No reason to continue if we get a match
                        break;

                    }


                }
                //We return the Obj_CountPrice
                return Obj_CountPrice2;
            }

            function calculateTotal() {
                //Here we get the total price by calling our function
                //Each function returns a number so by calling them we add the values they return together
                var cakePrice = getObj_TypePrice() + getObj_CountPrice() + getObj_CountPrice2();
                console.log (cakePrice);

                 
                //display the result
                var divobj = document.getElementById('totalPrice');
                divobj.style.display = 'block';
                divobj.innerHTML = "Yhteensä " + cakePrice + "€, Ilman alennusta " + cakePrice / 0.936 + " €";

            }
  • Вопрос задан
  • 49 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы