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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:33:35+00:00 2026-05-24T02:33:35+00:00

Here is the code I have written: function p_deal(id) { var card1_val = Math.floor(Math.random()

  • 0

Here is the code I have written:

function p_deal(id) {
    var card1_val = Math.floor(Math.random() * deck.length);
    var card2_val = Math.floor(Math.random() * deck.length);
        var card1 = deck[card1_val];
        var card2 = deck[card2_val];
    var hand = card1 + ", " + card2;
var res = card1_val + card2_val;

document.getElementById(id).innerHTML = hand;

and

function hit(id) {
    if (bucket == 0) {
        bucket = " ";
    }

    var card3_val = Math.floor(Math.random() * deck.length);
    var nhand = deck[card3_val];
    bucket = bucket + " " + nhand + ", ";
    bucket_val = bucket_val + card1_val + card2_val + card3_val;

    if (bucket_val >= 22) {
        var r = confirm("Bust! By " + nhand);
        if (r == true) {
            refresh();
        }
        else {
            refresh();
        }
    }

    document.getElementById(id).innerHTML = bucket;

    light = light + 1;

    if (light == 5) {
        alert("Five Card Blackjack! You Win!");
        refresh();
    }
}

The card_val variables within bucket val are from the p_deal(id) function. In order for the program to work, the card_val values must be the same each time both functions are called but they need to be regenerated each time the function is called (so multiple players can have different hands). However, as local variables I find it difficult to use them in another function. What can i do here?

  • 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-24T02:33:35+00:00Added an answer on May 24, 2026 at 2:33 am

    Looks like you want an object:

    function Hand(id) {
        this.elem = document.getElementById(id);
        this.bucket = "";
        this.bucketVal = 0;
        this.deal = function() {
            this.card1 = Math.floor(Math.random() * deck.length);
            this.card2 = Math.floor(Math.random() * deck.length);
            this.elem.innerHTML = deck[this.card1] + ', ' + this.card2;
        }
        this.hit = function() {
    
            var newCard = Math.floor(Math.random() * deck.length);
            this.bucket += " " + deck[nhand] + ", ";
            this.bucketVal += this.card1 + this.card2 + newCard;
    
            if (this.bucketVal >= 22) {
                var r = confirm("Bust! By " + nhand);
    
                refresh();
            }
    
            this.elem.innerHTML = this.bucket;
    
            light = light + 1;
    
            if (light == 5) {
                alert("Five Card Blackjack! You Win!");
                refresh();
            }
        }
    }
    
    var player1Hand = new Hand('player1Id');
    player1Hand.deal();
    player1Hand.hit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a snippet of code from a shell script I have written: for src
Here's the code I have: var commandsBuffer = List[String]() commandsBuffer ::= cmd.exe commandsBuffer ::=
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
I have problem with code. I have written a function for extracting a parameter,
JAVA Code Here is some part of my code that I have written in
I have written this piece of code here and I have linked it alright
I have written a javascript code to show users a random quote every 10
enter code here I have a table on SQL server 2005 with bigint primary
Here is the code I have to create an UIAlertView with a textbox. UIAlertView
Here's the code I have: from cStringIO import StringIO from lxml import etree xml

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.