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

100
Vistas
Loop is not incrementing

I am new to javascript.

I have to create a function that returns the next multiples of 5 based on a given number.But my loop repeats the information, it doesn´t increment the result.What am I doing wrong?

function proS(num, mult) {
  let arr = []

  for (var i = 1; i <= mult; i++) {
    arr.push(Math.ceil(num / 5) * 5)
  }
  return arr
}

proS(6, 4)

returns [10, 10, 10, 10]

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

you should use your formula to produce the initial value of num, then add 5 to it each time through the loop.

function proS(num, mult) {
  let arr = []
  num = Math.ceil(num / 5) * 5;
  for (var i = 1; i <= mult; i++, num += 5) {
    arr.push(num)
  }
  return arr
}

console.log(proS(6, 4))

about 4 years ago · Juan Pablo Isaza Denunciar

0

I won't write the answer, but I'll point you in the right direction. If you pay close attention arr.push(Math.ceil(num / 5) * 5) this bit of code is invariant. This means that you should probably add the variable i somewhere in there so that it actually returns a different output every iteration of the loop.

about 4 years ago · Juan Pablo Isaza Denunciar

0

thanks guys, I ended up doing this and it worked:

function proS (num, mult){
let arr = []
let res = (Math.ceil(num / 5) * 5)

for (var i = 1; i <= mult; i ++){
arr.push(res)
res += 5
}
return arr
}
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