Problem trying to perform a calculation

-2

I tried to print the W variable on the screen, but I think the js code has some error that does not allow this. How do I fix it?

JavaScript

function calcular() 
{
    var p = document.getElementById('produto_final');
    var q = document.getElementById('alimentacao');
    var wi = 9080;
    var w = ((wi / Math.sqrt(p)) - (wi / Math.sqrt(f)));

    document.getElementById('resultado').innerHTML = w;
}

HTML

<div class="container" align="center">
  <div class="col-md-5 col-md-offset-4">
    <form class="form-horizontal" action="#" method="#">
      <legend>Calculo da Potência:</legend>
      <div class="row">
        <div class="col-md-9">
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-6 control-label">Informe a variavel P:</label>
            <div class="col-sm-6">
              <input type="number" class="form-control" id="produto_final" maxlength="15">
            </div>
          </div>
          <div class="form-group">
            <label for="inputPassword3" class="col-sm-6 control-label">Informe a variavel F:</label>
            <div class="col-sm-6">
              <input type="number" class="form-control" id="alimentacao" maxlength="15">
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-8"><br>
                  <button type="button" class="btn btn-primary" onclick="calcular()">Calcular</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>
<p id="resultado"></p>
    
asked by anonymous 01.09.2018 / 05:00

1 answer

0

In your w variable, you are trying to calculate the square root of f , but there is no such declared variable.

To solve the problem, declare the variable f and assign a value to it or change its code to calculate the square root of q .

function calcular() 
{
    var p = document.getElementById('produto_final');
    var q = document.getElementById('alimentacao');
    var wi = 9080;

    //Alterar para calcular a raiz quadrada da variável q
    var w = ((wi / Math.sqrt(p)) - (wi / Math.sqrt(q)));

    document.getElementById('resultado').innerHTML = w;
}
    
01.09.2018 / 14:43