Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8657525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:32:31+00:00 2026-06-12T15:32:31+00:00

var num = [1,1]; var total = 0; var i = num.length; do {

  • 0
 var num = [1,1];
 var total = 0;
 var i = num.length;
 do {
    i++;
    num[i] = num[num.length-1] + num[num.length-2];
    total+=num[i];
    console.log(total);
 }
 while(num[num.length] < 4000000);

I’ve been working on the Project Euler questions for a day or two now to hopefully expand my knowledge and usefulness. On the second question I’ve been figuring out a (bad) way to get the fibonacci sequence. However my code will print “2” to console as it SHOULD but then stopping. Another issue I have is that just using the “while(X IS TRUE/FALSE) { DO STUFF }” just won’t work. Not a clue why.

I’m probably just making dumb mistakes but somebody please enlighten me 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:32:32+00:00Added an answer on June 12, 2026 at 3:32 pm

    Your num array has 2 elements, therefore num.length (and also i) are 2. The 1st statement in your do block is i++. Now i is 3.

    You’re setting num[3], which means num is now [1, 1, undefined, 1].

    Also, in your while, you are checking num[num.length]. Since arrays are zero-indexed, this will never work, as num.length is now 4.

    What I suggest is: increment i after setting the element. So, you push a new element, then increment the length counter.

    var num = [1, 1],
        total = 0,
        i = 2;  // we already know the length, no need to get it
    do {
        // we don't need the i++ here
        num[i] = num[i - 1] + num[i - 2]; // add the last 2 elements to the end
        total += num[i];
        console.log(total);
    }
    while (num[i++] < 4000000);  // "i++" increments i and returns its old value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look at this: $('form).submit(function (event) { $(':input.required').trigger('blur'); var num = $('.warning', this).length; alert(num);//Focus here!
I got this code: function zeroPad(num, places) { var zero = places - num.toString().length
for(var i=1; i<496; i++) { (function(num) { myApp.getTerm(num, function (term, def){ myApp.quizlet[0].terms[num] = {
gameDesign = { makeSeats: function( num ) { //num = number of seats var
var num = 10.00; if(!parseFloat(num)>=0) { alert(NaN); } else { alert(Number); } I want
var data = []; var id = 23; var num = 12; var dog_trialset
I've been working on getting a Coefficient of Variation equation ported from PHP to
I have a class: class MyClass { private var num : Int; } I
This is my ajax post <script language=JavaScript type=text/javascript> var num = 1; function ajax_post(){
var num = 1; num = num+1; //Gives 11 but var num = 1;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.