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

332
Vistas
How to print every number that is divisible by either 3 or 5, but not both?

I have a function threeOrFive(max). It should loop every number that is divisible by either 3 or 5 but not both. So it won't loop 15 since it's divisible by both numbers but will print out "3, 5, 6 , 9, 10, 12, 18".

The code I've tried is

function threeOrFive(max){
    for(let i = 0; i<max; i+=3, i+=5){
        console.log(i);
    }
}

and

function threeOrFive(max){
    for(let i = 0; i<max; i+=3){
        if(i+=3 % max === 0 && i+=5 % max === 0){
            return false;
        }
        console.log(i);
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use this function. This will return a array of all numbers that divisible by 3 or 5 but not by both.

const threeOrFive = max => {
    const store = [];

    for(let i = 0; i < max; i++){
        if (i%3==0 && i%5==0) continue;
        else if (i%3==0) store.push(i);
        else if (i%5==0) store.push(i);
    }

    return store;
}
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