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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:55:51+00:00 2026-06-11T10:55:51+00:00

Be gentle, I am VERY new to JavaScript: I am working on creating a

  • 0

Be gentle, I am VERY new to JavaScript:

I am working on creating a blackjack game – a few of the tutorials on CodeAcademy covered some of the basics, so I am attempting to take it a few steps further on my own. As a precursor to printing each of the player’s names, I created a function (showNames()) that would print “Bang, Boom!” into my “hud” section. This works when I (temporarily) assigned showNames() to the onclick function of my “Hit” button. However, when I try calling showNames() from my setupGame() function, it does not fire. Where am I going wrong? Code below:

index.html:

<!DOCTYPE html>
<html>
    <head>
        <title>Awesome Blackjack!</title>
        <link rel="stylesheet" type="text/css" href="common/css/default.css" />
        <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Galindo|Duru+Sans|Jolly+Lodger|McLaren' rel='stylesheet' type='text/css'>
        <script type="text/javascript" src="common/js/blackjack_controller.js"></script>
        <script type="text/javascript">
            function play() {
                if (setupGame()) {
                    showNames();
                    alert("Pow");
                } else {
                    alert("You must enter a number between 1 and 4.");
                }
            }
        </script>
    </head>
    <body>
        <div id="wrapper">
            <section id="hud">
                <div class="player" id="player1">
                    <div class="playerName">Drew</div>
                    <div class="playerScore">21</div>
                </div>
                <div class="player">
                    <div class="playerName">Dalton</div>
                    <div class="playerScore">12</div>
                </div>
                <div class="player">
                    <div class="playerName">Lindsey</div>
                    <div class="playerScore">23</div>
                </div>
                <div class="player">
                    <div class="playerName">Steven</div>
                    <div class="playerScore">9</div>
                </div>
            </section>
            <section id="table">
                <div id="controls">
                    <input type="button" name="start" id="start" value="Start" class="control start" onclick="play()"; />
                    <input type="button" name="hit" id="hit" value="Hit" class="control hit" onclick="showNames()"; />
                    <input type="button" name="stay" id="stay" value="Stay" class="control stay" />
                </div>
                <div id="dealer">
                    <div id="dealerName">Dealer</div>
                    <div id="dealerScore">19</div>
                    <div id="playArea">
                        <div class="card dealer club first">9</div>
                        <div class="card dealer club">9</div>
                        <div class="card dealer club">9</div>
                        <div class="card dealer heart king"></div>
                    </div>
                </div>
                <div id="playerWrapper">
                    <div class="playerArea a">
                        <div class="playerAreaName">Drew</div>
                        <div class="card club first">9</div>
                        <div class="card club">9</div>
                        <div class="card club">9</div>
                        <div class="card heart king"></div>
                    </div>
                    <div class="playerArea b">
                        <div class="playerAreaName">Drew</div>
                    </div>
                    <div class="playerArea c">
                        <div class="playerAreaName">Drew</div>
                    </div>
                    <div class="playerArea d">
                        <div class="playerAreaName">Drew</div>
                    </div>
                </div>
            </section>
        </div>
    </body>
</html>

blackjack_controller.js:

var numberOfPlayer = 0;
var players = new Array();
var name;
var names;

// Methods
function showNames() {
    document.getElementById("hud").innerHTML = "Bang, Boom!";
};

function setupGame() {
    numberOfPlayers = prompt("Please enter the number of players (up to 4).");
    if (numberOfPlayers > 0 && numberOfPlayers <= 4) {
        for (var i = 1; i <= numberOfPlayers; i++) {
            players[i] = new Player(prompt("Enter a name for player " + i + "."));
        }

        for (var i = 1; i <= numberOfPlayers; i++) {
            names += players[i].printName();
        }

        return true;
    }

    return false;
}

// Classes
function Player(name) {
    this.name = name;
    this.cards = new Array();
    this.score = 0;

    function printName() {
        return this.name + " ";
    }
}
  • 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-11T10:55:52+00:00Added an answer on June 11, 2026 at 10:55 am

    You defined your method wrong. It should be similar to the following:

    this.printName = function() {
        return this.name + " ";
    }
    

    DEMO

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

Sidebar

Related Questions

First, please be gentle, I know very little about DB design. I am working
Please be gentle, I'm very new to programming and only own one book which
I am very new to iPhone development, so please be gentle with me. I
I'm very new to programming, so be gentle. My goal is to make a
Please be gentle, as I'm still new to web programming and -very- new to
I am new to css and web design so please be gentle ;-) I
New but keen jquery user here, please be gentle :) I am using the
Totally new to Drupal so be gentle please! Let's say I have a number
OK, knowledgeable programmer-types, please be gentle... I'm having trouble getting a very simple, one-view
First question. Be gentle. I'm working on software that tracks technicians' time spent working

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.