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 4333250
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:22:02+00:00 2026-05-21T10:22:02+00:00

I have, in multiple parts of my code, snippits similar to this: function updateScore()

  • 0

I have, in multiple parts of my code, snippits similar to this:

function updateScore() {
    var currentPoints=0;
    for (nni=0;nni<currentSession.Questions.length+1;nni++) {
        currentPoints+=currentSession.Questions[nni].Score;
    }
    alert('hi');
    document.getElementById('quiz_score').innerHTML='%'+(currentPoints/currentSession.TotalPoints)*100
}

Everything works fine… until after the loop. This happens in multiple cases. The alert won’t even show after the loop ends. It’s like the function just stops…

I’m also having problems where the iterator (in this case, nni) stays global. Basically, I can’t use that variable ever again in my code because for some reason, if I change nni, it messes up the for loop. I’m obvisouly not doing something right. I’m a self tought Javascripter (basically googling anything I don’t know, I’ve never taken a lesson). I must be missing something about for loops.

Thanks if you can!

  • 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-05-21T10:22:03+00:00Added an answer on May 21, 2026 at 10:22 am

    What does the JS console report?

    If you’ve no idea what the JS console is, Google it, or add an exception handler to your function:

    function updateScore() {
        try {
            var currentPoints=0;
            for (nni=0;nni<currentSession.Questions.length+1;nni++) {
                currentPoints+=currentSession.Questions[nni].Score;
            }
            alert('hi');
            document.getElementById('quiz_score').innerHTML='%'+(currentPoints/currentSession.TotalPoints)*100
        } catch (err) {
            alert('Error ' + err.name + ': ' + err.message);
        }
    }
    

    Also, you’re letting the loop go too far; you should stop at .length, and not at .length + 1.

    And as has been noticed by others: you should really declare your nni variable using var.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What am looking for is to have multiple iFrames (or something similar) on a
I have 2 parts of code I want to execute. Both are conditionals if
I have multiple select boxes on the page all of which share the same
enter code here I have the following code to build select menus dynamically: $j(#id).load('create_menu.cgi',
I recall a while back seeing an experimental code visualization tool, with the intention
I am trying to split a collection into multiple collections while maintaining a sort
I have to work with another team that is developing in php, when I'm
I have a number of different projects, which are maturing to the level that
I work for a company which has multiple websites, all of sites somehow share
It's quite well known that IE6 does not support direct descendant selection with >

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.