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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:42:53+00:00 2026-05-29T10:42:53+00:00

// function scoreHandArray scores your hand function scoreHandArray(hand) { var score = 0; for

  • 0
// function scoreHandArray scores your hand
function scoreHandArray(hand) {
    var score = 0;
    for (i=0,i<hand.length,i++) {
        score = score + hand[i].value;
    };
    return score;
};

console.log( "You have the " + player[0].face + " of " + player[0].suit " and the " + player[1].face " of " + player[1].suit " for a score of " scoreHandArray(player));

Hello, it’s me again! This function here has an error in it that I cannot find, returning SyntaxError: Expected ';'. (I know it is the function, because commenting out the console.log changes nothing.) Function scoreHandArray takes an array of objects and returns the score of the objects. Full source code here:

// This code defines the Object constructor Card, used to make the card objects
var Card = function(card) {
    this.face = theFace(card);
    this.suit = theSuit(card);
    this.value = theValue(card);
};

// This code creates the Deck to be used.
var deck = [];
for ( i=0 ; i<52 ; i++ ) {
    deck.push( i );
};
for ( i=51 ; i>0 ; i-- ) {
    var random = Math.floor(Math.random()*i);
    var temp = deck[random];
    deck[random] = deck[i];
    deck[i] = temp;
};
// 0-12 is Spades.
// 13-25 is Hearts.
// 26-38 is Clubs.
// 39-51 is Diamonds.

// Now we create the hand of the player and dealer
var player = [];
var dealer = [];

// Now to deal a card to player
player.push(deck.pop());
dealer.push(deck.pop());

// and another
player.push(deck.pop());
dealer.push(deck.pop());

// function theFace gives the face of a card
function theFace( card ) {
    var faces = ["King","Ace","2","3","4","5","6","7","8","9","10","Queen","Jack"];
    return(faces[card%13]);
};

// function theValue uses 'switch' to determine points from a card
function theValue(card) {
    var value = card % 13;
    switch( value ) {

        case(0):
        case(11):
        case(12):
            value = 10;
            break;

        case(1):
            value = 11;
            break;

        default:
            value = value;
            break;

    };
    return value;
};

// function theSuit returns the suit of a card
function theSuit(card) {
    var suit;
    if(card>38) {
        suit = "Diamonds";
    }else if(card>25) {
        suit = "Clubs";
    }else if(card>12) {
        suit = "Hearts";
    }else {
        suit = "Spades";
    };
    return suit;
};

// function toObject the first (numbered) card of of a hand 
// and turns it into an Object with the desired properties
function toObject( hand ) {
    var card = hand.pop();
    if (typeof(card) !== "number") {
        hand.push(card);
    } else {
        var card = new Card (card);
        hand.unshift(card);
    };
    return hand;
};

toObject(player);
toObject(player);
toObject(dealer);
toObject(dealer);

// function scoreHandArray scores your hand
function scoreHandArray(hand) {
    var score = 0;
    for (i=0,i<hand.length,i++) {
        score = score + hand[i].value;
    };
    return score;
};

console.log( "You have the " + player[0].face + " of " + player[0].suit " and the " + player[1].face " of " + player[1].suit " for a score of " scoreHandArray(player));

Strange, now after replacing the ,s in the for loop with ;s, it now responds ReferenceError: expected ')'. What ) could it want? (The error appears to be in the last console.log line, as commenting it out makes the error dissapear.) I counted, in that line I have 2 ( and 2 )!

  • 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-29T10:42:53+00:00Added an answer on May 29, 2026 at 10:42 am

    It looks like your problem is here:

    for (i=0,i<hand.length,i++) {
        score = score + hand[i].value;
    };
    

    You need to replace the commas in the for loop with ;. Also, The semicolon after the } isn’t necessary.

    Additionally, using var i=0 at the beginning of the loop is preferred, and also prevents scoping issues due to referencing the global i variable.

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

Sidebar

Related Questions

function countChars(elm) { if (elm.nodeType == 3) { // TEXT_NODE return elm.nodeValue.length; } var
function dowork() { $(.wrappedElement).removeClass(wrappedElement); $(.wrappedElementout).removeClass(wrappedElementout); var a=$(div#DepPart select option:selected).val(); $(div#TestPart select option[value^=a]).addClass(wrappedElement); $(div#TestPart select
function averageCalculator (numvalues) { for(i=0, i <= numvalues, i++>) { var score = prompt(input
function validation(reg) { str = document.reg; if (str.name.value == ) { alert(Enter your name);
function Person(name){ this.name = name; } p = new Person('John'); log(typeof p.constructor); var f
function getUsername() { var userName = document.form.screen_name.value; document.getElementById(display).innerHTML = userName; var apiName = https://api.twitter.com/1/users/lookup.json?screen_name=
function test() { var flag1 = false; if ($('#field1').attr('value') || !$('#field1').attr('value')) { $.ajaxSetup({ cache:
function validateRequiredFields(formid) { var inputs = document.getElementsByClassName('required'); for(i=0;i<inputs.length;i++) { var FieldID = inputs[i].id; if(
Function calculate_attribute does not return a value; it only works through side effects. Often
function ff_chk_username_unique(element, action) { alert(element.value); alert(action); var actiona=http://localhost/myproject/check/check_username.php; var form_data = { username: element.value,

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.