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

179
Vistas
How to add string beside iterated value of for loop which are divisible by 3,5 & both?

I want to run a loop from 1 to 10 & ​want to print "divisible by 3" beside all the numbers which are divisible by 3 same for 5, print "divisible by both" beside the numbers which are divisible by 3 & 5 both as explained below.

Expected Output:-

  1
  2
  3 'divisible by 3'
  4
  5 'divisible by 5'
  6 'divisible by 3'
  7
  8
  9 'divisible by 3'
 10 'divisible by 5'
 11
 12 'divisible by 3'
 13
 14
 15 'divisible by both'
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is pretty straight forward by using the arithmetic operator %,

var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];


arr.forEach(x=>{

    if(x%3==0 && x%5==0){
    console.log(`${x} is divisible by both`);
  }else if(x%3 == 0){
        console.log(`${x} is divisible by 3`);
  }else if(x%5 == 0){
    console.log(`${x} is divisible by 5`);
  }else{
    console.log(`${x}`);
  }
})

,

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