Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
TheFundamentals

Multidimensional Arrays (Loop) - Chapter 6 Pg 201

Recommended Posts

***Sorry, it's from the To-Do Manager pg 204***

 

Hi, I need confirmation that my interpretation of the code below is correct and concerns the information displayed to the user.

 



tasks[];
 
if (task.value) {
        tasks.push(task.value);       
        message = '<h2>To-Do</h2><ol>';
 
        for (var i = 0, count = tasks.length; i < count; i++) {
            message += '<li>' + tasks + '</li>';
        }
        message += '</ol>';
 
        output.innerHTML = message;
        
    }
 

Each time the user presses submit, a task is added to the global tasks[] array. This causes the loop to swing into action and the task is visibly outputted to the user. 

 

When a new task is added, it appears to the user underneath each previously outputted task, which despite use of the submit button, don't appear to have been refreshed. That is to say, it 'appears' that the loop is outputting only the most recent task, when logic would dictate that the loop starts again and goes right through the tasks from [0] until i <  count, thus reprinting the original indexes it printed out previously (+1). 

 

Would I be correct in thinking that the fact that the previous tasks outputted to the user don't disappear and reappear owing to each iteration of the loop is because it is happening 'in the blink of an eye'?

 

Thanks. 

Share this post


Link to post
Share on other sites

Hello, and welcome to the forums.

 

Yes, your assumptions are correct. The rendering loop occurs so quickly that even though the loop is re-rendering each task every time you click the submit button, it happens so quickly, that your eye only perceives the final task being added to an existing list of tasks, which is in essence the intended effect.

  • Upvote 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...