Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

112
Visualizações
I'v got 3 input values and im tringing to sort them by size and add with js

I've got a form with 3 input values and I'm trying to sort them from smallest to highest and then do this.

  1. Add together the 2 shortest sides: 40 + 50 = 90.
  2. Multiply this number by 2: 90 x 2 = 180.
  3. Add the longest length to this number: 180 + 55 = 235.

I've got them sorted and pushed to the inputs array but I can't get my head around adding and multiplying them 😓.

Any help or sugestions guys.

     <form class="calc__container">

        <input 
        data-input 
        type="number"
        id="length"
        placeholder="Length">

        <input 
        data-input 
        type="number"
        id="width"
        placeholder="Width">

        <input 
        data-input 
        type="number"          
        id="hight"
        placeholder="Higth">
         
        <button class="submit__btn hover">Submit</button>


          <div class="ans-container">
            
            <p class="ans__p ">271 cm</p>
          </div>
        
     </form>

        let lInput = document.getElementById('length');
        let wInput = document.getElementById('width');
        let hInput = document.getElementById('hight');

        const submitBtn = document.querySelector('.submit__btn')

        let inputs = []

       submitBtn.addEventListener('click', function (e) {
       e.preventDefault();

          let allpointsArr = [
            Number(lInput.value), 
            Number(wInput.value), 
            Number(hInput.value)
          ];

         allpointsArr.sort(function(a, b){return a - b});
      
           points.push(allpointsArr)
           console.log(points);

          });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

in javascript sort is designed for to sort string values arrays not number array.

improve your sorting here try this:

const points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a - b}); 

you can refer from this link

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda