javascript – I have this error: Cannot read property 'value' of null, I dont understand why-ThrowExceptions

Exception or error:

I’m getting error in this code, I am making a calculator that can add, subtract, multiply and divide, the values of the numbers the code reads them correctly, but when I try to do the operations I get the error, and I don’t understand why the code doesn’t read it, can someone tell me what I’m doing wrong?
this is the code

function handleNumber(stNumber) {
    if(stNumber=="numero1")
    {
        Num1 = document.getElementById(stNumber).value*1;
    }else{
        Num2 = document.getElementById(stNumber).value*1;
    }
    return Num1, Num2;
}

function handleOperate() {
    var stOperation = document.getElementById(operaciones).value; 
    Execute(stOperation);
}

function Execute(stOperation) {
    var stResult = ""
    if(stOperation == "sumar"){
        stResult= sumar();
    } else if(stOperation =="restar"){
        stResult= restar();

    } else if(stOperation =="multiplicar"){
        stResult= multiplicar();

    } else if(stOperation =="dividir"){
        stResult= dividir();

    }

    document.getElementById("result").innerHTML = stResult;
}

this is the html

<div class="Container-operation">
            <span>Operación</span>
            <div class="Button-container"  id="operator">
                <select onchange="handleOperate()" class="Panel-container" id="operaciones">
                    <option value="sumar">Sumar</option>
                    <option value="restar">Restar</option>
                    <option value="multiplicar">División</option>
                    <option value="dividir">Multiplicación</option>
                  </select>
          </div>
          </div>
        </div>

        <div class="Equal">
          =
        </div>

        <div class="Result-container">
          <span id="result">Resultado</span>
        </div>
How to solve:

You’re passing a variable operaciones to getElementById(). If you don’t set a value for this variable it will not work. You probably want to pass a string 'operaciones' instead.

Leave a Reply

Your email address will not be published. Required fields are marked *