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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:45:34+00:00 2026-06-05T02:45:34+00:00

I’m trying to add cards to an array in a Deck object but for

  • 0

I’m trying to add cards to an array in a Deck object but for some reason push() is failing. I had this working earlier but after making some changes, I have effectively messed it up.
(The “testX” writes are there for debugging purposes)

<!DOCTYPE HTML>
<html>
<head>
<style> 
  #myCanvas {
    border: 1px solid #9C9898;
  }
  body {
    margin: 0px;
    padding: 0px;
  }
</style>
<script type="text/javascript">
<!--
//draws the game
window.onload = function() { 
    var canvas = document.getElementById("myCanvas"); 
    var context = canvas.getContext("2d"); 

    //draws the rectangles that will be the card        
    var cardHeight = 125,
        cardWidth = 80;

    context.beginPath();  

    //draws the top row of 5 cards  
    for(var x=0;x<5;x++){
        context.rect(10+(x*(cardWidth+10)),10,cardWidth,cardHeight);
    }

    //draws the bottom row of 5 cards
    for(x=0;x<5;x++){
        context.rect(10+(x*(cardWidth+10)),150,cardWidth,cardHeight);
    }

    //draws the deck
    context.rect(10+5*cardWidth+65,(150-10)/2,cardWidth,cardHeight);

    context.fillStyle = 'white';
    context.fill();
    context.lineWidth = 2;
    context.strokeStyle = 'black';
    context.stroke();   
};


function Deck(){
    //creates the unshuffled deck (loadedDeck) once to make the shuffling process faster
    var loadedDeck = new Array(),
        realDeck;

    this.loadTheDeck = function(){ //method 

        for(x=1;x<=13;x++){ 
            this.loadedDeck.push(x+" Spades"); //<---issue line (all 4 are failing though this is the first)
            this.loadedDeck.push(x+" Clubs");
            this.loadedDeck.push(x+" Hearts");
            this.loadedDeck.push(x+" Diamonds");
        }
        document.write(this.loadedDeck);
    };
    this.loadTheDeck(); //creates the unshuffled deck when the Deck is instantiated


    //resets the deck and randomizes
    this.shuffle = function(){ //method 

        //creates the real deck
        this.realDeck = this.loadedDeck;

        //write shuffle function
    };
    this.shuffle(); //shuffles the Deck when instantiated
}

document.write("test-1");
var myDeck = new Deck();
document.write("test0");
document.write(this.realDeck);
document.write("test1");    
-->
</script>
 </head>
 <body>
<canvas id="myCanvas" height="300" width="600"></canvas>

 </body>
 </html>

Here is a demo of the code: http://jsfiddle.net/NfmsR/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-06-05T02:45:35+00:00Added an answer on June 5, 2026 at 2:45 am

    When you run this line:

    this.loadedDeck.push(x+" Spades");
    

    You are using the this.loadedDeck array. Have you defined it as part of the Deck object? Nope:

    var loadedDeck = new Array(),
        realDeck;
    

    Change the declaration to this and it should work:

    this.loadedDeck = []; // I'd use [] instead of new Array().
    this.realDeck = [];
    

    As @j08691 pointed out, you need to change realDeck to this.realDeck as well because you’re calling it similarly here:

    this.shuffle = function(){ //method 
    
        //creates the real deck
        this.realDeck = this.loadedDeck;
    
        //write shuffle function
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,

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.