Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
¿Cómo agregar una cadena al lado del valor iterado del bucle for que es divisible por 3,5 y ambos?

Quiero ejecutar un ciclo del 1 al 10 y quiero imprimir "divisible por 3" al lado de todos los números que son divisibles por 3 lo mismo para 5, imprimir "divisible por ambos" al lado de los números que son divisibles por 3 y 5 ambos como se explica a continuación.

Rendimiento esperado:-

 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 answers
Answer question

0

Es bastante sencillo usar el operador aritmético % ,

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!