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

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

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 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!