This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by German
almost 9 years

FINALLY!! Need your advices (Dice Challenge)

I’m so happy, really took me two days to make this :D, i know it’s too simple but im just a beginner in this and im really so happy i made this all by myself.

I want you guys to tell me if there’s another way (shorter and easy) to make this or maybe if you see mistakes or something that the code doesn’t really need

HTML/PHP:

<!DOCTYPE html>
<html>
    <head>
        <title>Your own do-while</title>
        <link type='text/css' rel='stylesheet' href='style.css'/>
    </head>
    <body>
    <p>Lets see how many times we need to trow a dice to get 6</p>
    <?php
        $trowcount = 0;
        do{
            $trow = rand(1,6);
            $trowcount++;
            if($trow){
                switch ($trow) {
                    case 1:
                        echo "<p class=dice>1</p>";
                        break;
                    case 2:
                        echo "<p class=dice>2</p>";
                        break;
                    case 3:
                        echo "<p class=dice>3</p>";
                        break;
                    case 4:
                        echo "<p class=dice>4</p>";
                        break;
                    case 5:
                        echo "<p class=dice>5</p>";
                        break;
                    case 6:
                        echo "<p class=dice>6</p>";
                        break;
                    default:
                        echo "<p>The dice flew away!!</p>";
                }
            }
        }while($trow < 6);
        $w1 = "";
        $w2 = "tries";
        
        if($trowcount == 1){
        $w1 = "just";
        $w2 = "try";
        };
        echo "<p>¡There you go! it took $w1 $trowcount $w2 to get 6 </p>";
    ?>
    </body>
</html>

CSS:

.dice {
    height: 50px;
    width: 50px;
    border-radius: 5px;
    background-color: grey;
    text-align: center;
    font-weight: bold;
    font-family: sans-serif;
    color: white;
    margin: 10px;
    display: inline-block;
    line-height: 50px;
    font-size: 25px;
}

Answer 556f5d839113cb945b000139

3 votes

Permalink

whoa congratulations if it works it should be fine

points
Submitted by sofiabeans27
almost 9 years

Answer 558045f7e39efeb18b0000fe

2 votes

Permalink

Great job man, it works as expected

points
Submitted by druzhok100
almost 9 years

Answer 561500a086f552c24200038b

0 votes

Permalink

Awesome

points
over 8 years