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

362
Views
What am I doing wrong in this loop? js

I am trying to solve this loop but I can't solve it

You must create a function called loopDePares that receives a number as a parameter and loops from 0 to 100, displaying each loop number on the console. If the number of the iteration, added to the number passed by parameter, is even, it will show in the console “The number x is even”.

what i did was this

function loopDePartes(numero){
  for (let i = 0; i <numero; i++){
    console.log(i+numero % 2 ? i : "x")
  }
}

loopDePartes(10)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You had one math error, and one comparison error.

i+numero needs to be wrapped in parens so it take precedence over the modulus operator.

Your ternary was checking the truthiness of the output of that math, instead of checking whether it was even or odd.

Both are corrected below:

function loopDePartes(numero){
  for (let i = 0; i < 100; i++){
    console.log((i+numero) % 2 == 1 
      ? i 
      : `The number ${i+numero} is even`
    )
  }
}

loopDePartes(10)

(Actually, the more I reread your question the less I understand what is the expected output; I think this is what you're looking for but I may have misinterpreted what you meant by "display the loop number", and what "x" is supposed to be in "The number x is even".)

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!