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

158
Views
For Loops that append based on negative indices - Javascrip

Goal: write a loop that appends the sum of the last two items in [fib] to the end of [fib] for 20 loops and find the values of the last iteration.

Code Thus Far

let fib = [0,1]

let accumulator = 0

for (t=0;t<20;t++){
  endingDigits = fib[-1]+ fib[-2];
  accumulator =+ Number(accumulator) + Number(endingDigits);
  fib.push(endingDigits);
  t++;
}
console.log(fib)

Results I keep getting NaN - Which is why Rap the two negative indices in the number method.

Thanks for the help!

about 4 years ago · Santiago Gelvez
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!