How to get input value and make an account

2

Hello, I'm new to the programming area, and I'm learning javascript. I decided to make a tool that calculated the AMA (slaughter, death, care) of a game I play. The bill is to add the killings with assists and divide by the deaths. So far so good. I made a page using bootstrap, and now I want to get the value placed there, to make the count, and I do not know. I'll put some parts of the code here.

<div class="row">
        <div class="col-md">
            <p>Digite o número de abates</p>
            <div class="input-group input-group-sm mb-3">
                <div class="input-group-prepend">
                <span class="input-group-text" id="inputGroup-sizing-sm">Abates</span>
                </div>
                <input type="number" class="form-control" id="abates" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
            </div>
        </div>

        <div class="col-md">
            <p>Digite o número de mortes</p>
            <div class="input-group input-group-sm mb-3">
                <div class="input-group-prepend">
                <span class="input-group-text" id="inputGroup-sizing-sm">Mortes</span>
                </div>
                <input type="number" class="form-control" id="mortes" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
            </div>

        </div>

        <div class="col-md">
            <p>Digite o número de assistências</p>
            <div class="input-group input-group-sm mb-3">
                <div class="input-group-prepend">
                <span class="input-group-text" id="inputGroup-sizing-sm">Assistências</span>
                </div>
                <input type="number" class="form-control" id="assistencias" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
            </div>
            <br>

            <button onclick="calcularAma()" type="button" class="btn btn-primary" id="botao-calcular">Calcular</button>
        </div>
        </div>

This is a part of html. Here is my question, how to get the input value and calculate? Sorry, I looked, but I could not find it on google. I'm totally lost.

var abates = document.getElementById('abates');
var mortes = document.getElementById('mortes');
var assistencias = document.getElementById('assistencias');

var resultado;

function calcularAma(){
document.getElementById('abates').value;
document.getElementById('mortes').value;
document.getElementById('assistencias').value;
}

(If you need to, I paste the whole code into the pastebin.)

    
asked by anonymous 26.05.2018 / 02:56

1 answer

0

You can do this by converting only what is added to parseInt :

function calcularAma(){
   var abates = parseInt(document.getElementById('abates').value);
   var mortes = document.getElementById('mortes').value;
   var assistencias = parseInt(document.getElementById('assistencias').value);
   
   var resultado = (abates+assistencias) / mortes;

   console.log(resultado);   
}
<div class="row">
  <div class="col-md">
      <p>Digite o número de abates</p>
      <div class="input-group input-group-sm mb-3">
          <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroup-sizing-sm">Abates</span>
          </div>
          <input type="number" class="form-control" id="abates" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
      </div>
  </div>

  <div class="col-md">
      <p>Digite o número de mortes</p>
      <div class="input-group input-group-sm mb-3">
          <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroup-sizing-sm">Mortes</span>
          </div>
          <input type="number" class="form-control" id="mortes" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
      </div>

  </div>

  <div class="col-md">
      <p>Digite o número de assistências</p>
      <div class="input-group input-group-sm mb-3">
          <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroup-sizing-sm">Assistências</span>
          </div>
          <input type="number" class="form-control" id="assistencias" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
      </div>
      <br>

      <button onclick="calcularAma()" type="button" class="btn btn-primary" id="botao-calcular">Calcular</button>
  </div>
  </div>
    
26.05.2018 / 03:10