Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda