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

  • Home
  • SEARCH
  • 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 8488145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:27:04+00:00 2026-06-10T21:27:04+00:00

For some reason the second for loop is starting at 1. I do realize

  • 0

For some reason the second for loop is starting at 1. I do realize that first for loop i starts at one. That’s is meant to be. However, even though j for loop says to start at 0, it starts at 1 anyways.

var findWinners = function (playersRay) {
    var players = playersRay;
    var results = new Array();

    //getdealers dealers hand and info
    var dealerHand = players[0]
    var dealerScore = dealerHand.getScore()
    var dealerBust = dealerScore > 21 ? true : false;

    //loops through all players; skips dealer (array position 0)
    var numPlayers = players.length;
    for (var i=1; i<numPlayers; i++) {
            //loops through all the players hands.
            //player might have more than 1 hand if he splits his cards
        var player = players[i];
        var numHands = player.length;
        results[i] = new Array();

        for (var j=0; j<numHands; j++)
            var handScore = player[j].getScore();

            if (handScore > 21) {
                results[i][j] = false;              
            }
            else if (dealerScore > 21) {
                results[i][j] = true;
            }
            else if (handScore > dealerScore) {
                results[i][j] = true;
            }
            else {
                results[i][j] = false;
            }
    }
    return results;
}

It returns this: [undefined, [undefined, true]]

It should return this: [undefined, [true]]

Just in case you want to know. A sample playersRay is: [Object, [Object]]
The object has information about the dealer’s or player’s blackjack hand.

Link to full code: https://docs.google.com/open?id=0BxvwY0fUFc3aMTdTOXU0b0ttamM

  • 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-10T21:27:06+00:00Added an answer on June 10, 2026 at 9:27 pm

    In Javascript, when you omit the curly braces around a statement, it only runs the first line. The behavior appears to omit only the first index, when I suspect there’s only two. So if you add some more to iterate, you should notice it’s actually just running the last index.

    For example:

    for (var i = 0; i < 10; i++)
        console.log('First line: ', i);
    
        console.log('Second line: ', i);
    

    http://jsfiddle.net/MMQD8/

    Gives:

    First line: 0
    First line: 1
    First line: 2
    First line: 3
    First line: 4
    First line: 5
    First line: 6
    First line: 7
    First line: 8
    First line: 9
    Second line: 10
    

    MDN explains it thusly:

    statement

    A statement that is executed as long as the condition
    evaluates to true. To execute multiple statements within the loop, use a block
    statement ({ … }) to group those statements.

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

Sidebar

Related Questions

Is there some reason that identical math operations would take significantly longer in one
For some reason there's a variable called d that is defined immediately after I
For some reason, my spec isn't passing. It appears that @categories isn't getting to
I'm trying to loop an exception, but for some reason its not giving me
For some reason when I iterate through an array using foreach loop a condition
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
for some reason when I try to call CocoaAsyncSocket's onSocket:didReadData:withTag method, it's failing and
For some reason I can't detect I can't set a z index for any
For some reason the postback event keeps firing for my button. If I place
For some reason this isn't working, am I missing something obvious? RewriteRule ^(.*)infopopup.html$ /acatalog/infopopup.html

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.