This forum is now read-only. Please use our new forums! Go to forums
banner
Close banner
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
whoa congratulations if it works it should be fine
Answer 558045f7e39efeb18b0000fe
Answer 561500a086f552c24200038b
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency