samedi 30 novembre 2019

Select in if-Statement

I am writing a simple calculator where the result depends on what selector has been chosen and the issue is that it doesn't work because code stops in seconde if statement. I checked the if statement a few times and it has true on the exit иге I'm new in coding and I don't know can I put the callback function into the If-statement or not and perhaps that is why It doesn't work.

<strike><div class="section"> 
    <div class="container">
      <div class="row justify-content-center">
        <div class="col-md-8 text-center">
          <h2 class="mb-4 section-title">Calculator</h2>
        </div>
        <div class="calculator">
          <div class="stri area">
            <div class="stri_text area_text">Type of material</div>
            <div class="stri_input area_input"><select><option value="matt">Matt</option><option value="glossy">Glossy</option><option value="satin">Satin</option><option value="Тканевый">Тканевый</option></select></div>  
          </div>
          <div class="stri material">
            <div class="stri_text material_text">Area of a ceiling</div>
            <div class="stri_input material_input"><input class="expenses-item"></div>  
          </div>
          <div class="stri angles">
            <div class="stri_text anglesl_text">Number of corners</div>
            <div class="stri_input angles_input"><input class="expenses-item"></div>  
          </div>
          <div class="stri chandelier">
            <div class="stri_text chandelier_text">Number chandeliers</div>
            <div class="stri_input chandelier_input"><input class="expenses-item"></div>  
          </div>
          <div class="stri light">
            <div class="stri_text light_text">Number of spotlights</div>
            <div class="stri_input light_input"><input class="expenses-item"></div>  
          </div>
          <div class="stri pipe">
            <div class="stri_text pipe_text">Bypassing of pipes</div>
            <div class="stri_input pipe_input"><input class="expenses-item"></div>  
          </div>
          <div class="result_btn">
            <button class="btn btn-lg">Рассчитать</button>
          </div> 
          <div class="result">
            <div class="stri_text result_text">TOTAL:</div>
            <div class="result_num preserve-whitespace" id="result-item">&nbsp</div>
          </div>
        </div>
      </div>
    </div>
  </div></strike>
    'use strict';

    let selectSelector = document.getElementsByTagName('select'),
        optionsSelector = document.getElementsByTagName('option'),
        expensesItem = document.getElementsByClassName('expenses-item'),
        resultItem = document.getElementById('result-item'),
        expensesBtn = document.getElementsByTagName('button')[1]; 

    let sum;


    expensesBtn.addEventListener('click', function () {
        if (isNaN(expensesItem[0].value) || isNaN(expensesItem[1].value) || isNaN(expensesItem[2].value) || isNaN(expensesItem[3].value) || isNaN(expensesItem[4].value)) {

            resultItem.textContent = "Введите числовые данные ..."; 

            } else if (selectSelector.addEventListener('select', function () {
                optionsSelector[0].value == "mat";
                })) {

                sum = +expensesItem[0].value + +expensesItem[1].value + +expensesItem[2].value + +expensesItem[3].value + +expensesItem[4].value;
                resultItem.textContent = sum;

        }
    });
```````````````````````````````````````````````````````````````````````````````````````````````````

Aucun commentaire:

Enregistrer un commentaire