dcsimg
www.webdeveloper.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 33

Thread: [RESOLVED] Quick Help needed, PLEASE! Help wit my assignment(Triple Roll game)

  1. #1
    Join Date
    Dec 2013
    Posts
    23

    resolved [RESOLVED] Quick Help needed, PLEASE! Help wit my assignment(Triple Roll game)

    I am new to Java Script and I am currently trying to pass the 1st assignment. I got stuck because I wasted too much time on other things. Can sobedy help me finish the game?? I know I d have to create some functions to do it but assignment is due on Friday I must pass it! . I do not wont to use the arrays to make it simpler and more understanduble for me. PLEASE HELP
    this is the code I have.

    <html>
    <body>
    <head>
    document.write("sasdad")
    </head>
    <script type="text/javascript">
    var gameover != false;
    var credit = 100;
    var bet = 0;
    var d1 = Math.floor((Math.random()*6)+1);
    var d2 = Math.floor((Math.random()*6)+1);
    var d3 = Math.floor((Math.random()*6)+1);
    if (confirm("Do you want to play tripple roll?") == true)
    {
    document.writeln("Welcome to ACME casino Ltd. Please gamble with care.");
    document.writeln("<p>Tripple Roll Game <br>" + "<p> <b>Rules: </b>");
    document.writeln("<p>You are betting and than 3 die are thrown.<br>");
    document.writeln("<p>For each round of the game, You can bet between 1 and 100.<br>");
    document.writeln("<p>Game has maximum of 10 rounds. At the end of each round You can continue or quit.<br>");
    document.writeln("<p>If 3 die all show value of 1 than You win your bet * 50 + Your original stake back.");
    document.writeln("<p>If the 3 die all show three same values (other than the value 1), then You win your bet * 30 + Your original stake back.<br>");
    document.writeln("<p>If 2 die show the same value, then You win your bet * 8 + Your original stake back.<br>");
    document.writeln("<p>If none of these prizes have been won, if the total of die come to 15 or more, You win 2 * Your bet + orginal stake back<br>")
    document.writeln("<p>If one die shows a 6, or all the values of the die are odd numbers, then You will get Your bet back<br>")
    document.writeln("<b><p>Betting Stuck: </b>" + credit);
    }
    else
    {
    document.writeln("See you later")
    }
    </script>
    </body>
    </html>

    // I am trying to create the button when user decide to play the game. later on I know I d have to make some functions like:
    var rolldice = function() // puts all 3 dice rolls into a function to be easily called.
    {
    die1 = Math.round(Math.random()*6); // random number generators for the 3 dice
    die2 = Math.round(Math.random()*6); // dieX is an integer (round number) in the range of 1 to 6
    die3 = Math.round(Math.random()*6);
    }
    and another function for updating the winnings and placing the bet which I m not sure about, can somebody please help??

  2. #2
    Join Date
    Dec 2013
    Posts
    23
    I figure out most of the staff. (I think) is kind of working. I need to tested as well so if somebody has any good quick solution for testing my triple roll game please share that with me. I still need to stop user from placing the decimal bets and I d like to have a function to check if numbers on the die are odd or not. Also I m strugling how to ask user/player if he d like to continue the game or quit the game......
    instead of printing the rules in the document.writeln function I stick them inside the pop up box at the beginning of the game. I have 3 different functions, place bet, throw die and update winnings function. Can somebody help me how to check the odd numbers, stop user from betting decimal and ask if he wants to quit or play. Thanks, even that it has been no replays to my post, which is probably nothing interesting for most of you I m thinking positive and waiting for somebody to help me a bit.
    I need to test my software as well so if somebody has some quick solutions for debugging the game please share that with me.

  3. #3
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    Post your updated version of code and place it within forum CODE tags.

  4. #4
    Join Date
    Dec 2013
    Posts
    23
    I have thought I manage to get the right code but I was wrong. I have try a simple version of it but is not working still. Here is my cod of simple if statment and for loop:
    <html>
    <body>
    <script type="text/javascript">
    var credit = 100;
    var d1;
    var d2;
    var d3;
    var round = 0;
    var bet=0;
    var betInput;

    //function isOdd(num){return num % 2;}

    d1 = Math.floor((Math.random()*6)+1);
    d2 = Math.floor((Math.random()*6)+1);
    d3 = Math.floor((Math.random()*6)+1);

    for(round=0;(round<11);round++)
    {
    do
    {
    betInput = window.prompt("Enter bet between 1 and 100", "0");
    bet = parseInt(betInput);
    }
    while ((isNaN(bet) == true) && ((bet<1) || (bet>100)) && (credit<0));
    if (d1 + d2 + d3 == 3)
    {

    document.writeln("<p>Well done you have won your bet * 50 + your orginal stake" + (credit + (bet*50) + bet) + "<br>");
    }
    else if (((d1 == d2) && (d2 == d3) && (d3 == d1)) && (d1 + d2 + d3 != 3))
    {

    document.writeln("<p>Well done you have won your bet * 30 + your orginal stake" + (credit + (bet*30) + bet) + "<br>");
    }
    else if ((d1 == d2) || (d2 == d3) || (d3 == d1))
    {

    document.writeln("<p>Well done you have won your bet * 8 + your orginal stake" + (credit + (bet*8) + bet) + "<br>");
    }
    else if (d1+d2+d3>15)
    {

    document.writeln("<p>Well done you have won your bet * 2+ your orginal stake" + (credit + (bet*2) + bet) + "<br>");
    }
    else if ((d1==6) || (d2==6) || (d3==6))
    {

    document.writeln("<p>Well done you have won your stake back" + (credit + bet )+bet+ "<br>");
    }
    else
    {

    document.writeln("<p>You have lost" + (credit - bet )+ "<br>");
    }




    }
    if (credit == 0)
    {
    document.writeln("<p>You have lost" );
    }
    </script>
    </body>
    </html>
    it is not working correctly. If somebody can give me some clues I would be glad.
    Thank you

  5. #5
    Join Date
    Dec 2013
    Posts
    23
    there is a function as a comment because is not working correctly either. My deadline is tomorrow and I m in trouble

  6. #6
    Join Date
    Dec 2013
    Posts
    23
    I know that a function for rolling die will look like that:
    var rollDices = function ()
    {
    d1 = Math.round(Math.random()*6);
    d2 = Math.round(Math.random()*6);
    d3 = Math.round(Math.random()*6);
    document.writeln("<br>" + "<b>Die 1 = </b>" + d1 + "<br>" + "<b>Die 2 = </b>" + d2 + "<br>" + "<b>Die 3 = </b>" + d3 + "<br>")
    }

  7. #7
    Join Date
    Dec 2013
    Posts
    23
    there has to be 2 other functions to make it nice and simple: place bet and calculate winnings. And I cannot and do not know how to make them work

  8. #8
    Join Date
    Dec 2013
    Posts
    23
    I am currying on and trying my luck. I have spend already 6h sitting in my room front of the PC.
    I have something like that, I know that is not even close to finish but trying!!
    <html>
    <body>
    <script type="text/javascript">
    var credit = 100;
    var d1;
    var d2;
    var d3;
    var round = 0;
    var bet;
    var betInput;

    var placeBet = function()
    {
    betInput = window.prompt("Please enter your bet between 1 and 100")
    bet = parseInt(betInput);
    }

    var rollDices = function ()
    {
    d1 = Math.round(Math.random()*6);
    d2 = Math.round(Math.random()*6);
    d3 = Math.round(Math.random()*6);
    document.writeln("<br>" + "<b>Die 1 = </b>" + d1 + "<br>" + "<b>Die 2 = </b>" + d2 + "<br>" + "<b>Die 3 = </b>" + d3 + "<br>")
    }
    placeBet()
    {
    rollDices()
    }
    </script>
    </body>
    </html>

  9. #9
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    Although I'm pretty tired, I'll try to help!

  10. #10
    Join Date
    Dec 2013
    Posts
    23
    much appreciate

  11. #11
    Join Date
    Dec 2013
    Posts
    23
    in my simple code with if/else if statments I am still getting wrong things. it should be like that... If the 3 die all show a 1 , then you will win 50 times your bet plus the original stake back; If the 3 die all show the same value other than 1 then you win 30 times your bet plus your original stake back; If 2 die show the same value, then you win 8 times your bet plus your original stake; If you don't meet any of the requirements but the values of die add up to 15 or more, then you win 2 times your bet plus the original stake;If one of the die is a 6 or all 3 of the die are odd numbers, then you get your bet back; anything else user loses their bet

  12. #12
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    Bionoid will help
    Last edited by tech_soul8; 12-12-2013 at 04:55 PM.

  13. #13
    Join Date
    Dec 2013
    Posts
    23
    I m looking forward to help somebody in the future I already have the book javascript for dumies I ll put more of my own time and invation to study = new years resolution == true

  14. #14
    Join Date
    Dec 2013
    Posts
    23
    var placeBet = function()
    {
    betInput = window.prompt("Please enter your bet between 1 and 100")
    bet = parseInt(betInput);
    }
    maybe I am right or need more code I am waiting for some ideas fly to my head

  15. #15
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    I didn't really take a look at all of your code, but at a glance first thing you're doing wrong is dynamically generating all of the content. It would be much easier and nicely formatted if you first had built the html part of the code and have used JavaScript only to do the calculations etc...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles