Jump to content

Completely new to this but trying to make a dice script


captainphpnoob

Recommended Posts

Hello. My name is Sam and I'm learning php as a hobby so I understand if more urgent matters are taken care of before mines! :)
 
My goal for now is to create a dice script where I roll a die and it prints out how many times it had to roll before it lands on a 6.
 
Here is the code I have thus far.

 

 

 

<?php
        //write your do-while loop below
        $do {$roll = rand(1,6);
            $rollCount ++;
           switch ($roll) {
               case(1):
               case(2):
               case(3):
               case(4):
               case(5):
                break;
                case(6):
                    echo "<p>It took {$rollCount} times!</p>";
                    break;
           }
                           
          }
 
    ?>
 
 
but nothing happens. Sorry for the trouble. I find php fun so far and would love to learn more. Thanks for any help!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.