Problem trying to perform a calculation

Asked

Viewed 44 times

-2

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

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>
  • 3

    The error, you declare q, but uses f

1 answer

0


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

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;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.