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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:49:55+00:00 2026-06-18T05:49:55+00:00

I am trying to determine what the total is equal to and then do

  • 0

I am trying to determine what the total is equal to and then do a job pertaining to each selection. My first selection is if the total is 2, 3, or 12, then you lose. If it is a 7 or a 11, you lose. Anything else the point is established. First my code looked like this, but every single time, it went to else. The total is being calculated through 2 random numbers added together using this function:

   Math.floor(Math.random()*6+1);

function game()
 {
if(total==2 || total==3 || total==12)
    {
        alert("You lose. Please start a New Round");
    }
if(total==7 || total==11)
    {
        var temp= 2 * bet;
        alert("You win $" + temp);
    }   
else 
    {
        alert("Point Established. Roll again.");
        var point=total;
        setTimeout(rolldice2,3000);
    }
 }

Then I changed it to this:

 function game()

 {
if(total==2 , 3 , 12)
    {
        alert("You lose. Please start a New Round");
        return;
    }
if(total==7 , 11)
    {
        var temp= 2 * bet;
        alert("You win $" + temp);
        return;
    }   
else 
    {
        alert("Point Established. Roll again.");
        var point=total;
        setTimeout(rolldice2,3000);
    }
 }

But it just says you lose no matter what. Then I finally took out return. It does the first 2 and not else. I want to be able to choose one- depending on what the variable total is equal to- and then perform its jobs and then leave the function.

  • 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-18T05:49:56+00:00Added an answer on June 18, 2026 at 5:49 am

    In your case total variable is undefined

    Pass total to your function and do a switch statement

     function game(total)
     {
        switch(total)
        {
            case 2 : 
            case 3 :
            case 12 : {
                        alert("You lose. Please start a New Round");
                        return;
                      }
            case 7 : 
            case 11 :
                     {
                        var temp= 2 * bet;
                        alert("You win $" + temp);
                        return;
                     }   
            default : 
                    {
                        alert("Point Established. Roll again.");
                        var point=total;
                        setTimeout(rolldice2,3000);
                    }
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to determine a rank for each key in a hash against the
I'm trying to determine the total size of a Service Broker Queue and transmission
I am trying to find a way to determine the total and available disk
I'm trying to determine the total elapsed time to complete a set of processes
I am trying to use the With Rollup function to determine the TOTAL number
Hi I am trying to echo out check boxes, and then determine if they
I'm trying to determine if a database of a certain name exists and then
I'm trying to determine the count of each array within a multidimensional associative array.
I'm trying to use Rubygame to determine each of a string's character widths as
Trying to determine if it is possible to bind the SelectedValue of a ComboBox

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.