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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:08:16+00:00 2026-06-05T22:08:16+00:00

In my script to generate a playing card, it’s generating a 0, even though

  • 0

In my script to generate a playing card, it’s generating a 0, even though my random generator is adding a 1, so it should never be 0. What am I doing wrong?! If you refresh, you’ll eventually get a “0 of Hearts/Clubs/Diamonds/Spades”:

var theSuit;
var theFace;
var theValue;
var theCard;

// deal a card
function generateCard() {
    var randomCard = Math.floor(Math.random()*52+1)+1;  
    return randomCard;
};

function calculateSuit(card) {
    if (card <= 13) {
        theSuit = "Hearts";
    } else if ((card > 13) && (card <= 26)) {
        theSuit = "Clubs";      
    } else if ((card > 26) && (card <= 39)) {
        theSuit = "Diamonds";
    } else {
        theSuit = "Spades";
    };  

    return theSuit;
};

function calculateFaceAndValue(card) {
    if (card%13 === 1) {
        theFace = "Ace";
        theValue = 11;
    } else if (card%13 === 13) {
        theFace = "King";
        theValue = 10;          
    } else if (card%13 === 12) {
        theFace = "Queen";
        theValue = 10;
    } else if (card%13 === 11) {
        theFace = "Jack";
        theValue = 10;
    } else {
        theFace = card%13;
        theValue = card%13;
    };

    return theFace;     
    return theValue
};

function getCard() {
    var randomCard = generateCard();        
    var theCard = calculateFaceAndValue(randomCard);
    var theSuit = calculateSuit(randomCard);            
    return theCard + " of " + theSuit + " (this card's value is " + theValue + ")";
};

// begin play
var myCard = getCard();
document.write(myCard);`
  • 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-05T22:08:18+00:00Added an answer on June 5, 2026 at 10:08 pm

    This line is problematic:

    } else if (card%13 === 13) {
    

    Think about it: how a remainder of division to 13 might be equal to 13? ) It may be equal to zero (and that’s what happens when you get ‘0 of… ‘), but will never be greater than 12 – by the very defition of remainder operation. )

    Btw, +1 in generateCard() is not necessary: the 0..51 still give you the same range of cards as 1..52, I suppose.

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

Sidebar

Related Questions

I created a rails model by doing script/generate model Customer name:string address:string city:string state:string
We have script/generate migration add_fieldname_to_tablename fieldname:datatype syntax for adding new columns to a model.
I've been playing with idea to make a script to generate 2-characters words from
I run script/generate model query edit query.rb in models.. class Query < ActiveRecord::Base #I
I've scaffolded Things element: script/generate scaffold wip/thing name:string and got some invalid function call
I have ruby on rails installed on my ubuntu 8.10 desktop. Script/generate came up
I have this script to generate an XML file for an RSS feed. Works
I'd like to run the rails generate script and create a model that belongs
I'm using the succinctly named googlechartseasyphpclass script to generate google charts from numbers I'm
I'm looking for a script that will generate jpg thumbnails on the fly (in

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.