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

281
Views
funtion wont print enter forloop referencing an array

I somehow can't get my for loop inside of a function to print elements in an array. could someone point out why javascript is not allowing the iteration to occur and only printing the first element?

const data1 = [17, 21, 23];

function printForecast(array) {
  for (let i = 0; i < array.length; i++) {
    let dayVsDays = i <= 1 ? 'day' : 'days'
    return `The temp is ${array[i]}ºC in ${[i+1]} ${dayVsDays}`;
  }
}

console.log(printForecast(data1))

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Don't use return inside a loop unless you want to return the result of an specific iteration; this is why you only get the first iteration.

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!