Aims:
echo
statements,
assignment statements,
conditional statements, and sequences of statements, as well as
return
statements
return
statement, or several return
statements, rather than just a single return
statement
void
)bakuchi.html
contains this form:
<form action="bakuchi.php" method="get"> <input type="radio" name="bet" value="even" /> <input type="radio" name="bet" value="odd" /> <input type="submit" /> </form>
bakuchi.php
which
doesn't use any programmer-defined functions
$bet = $_GET['bet']; if ( ( $bet == 'even' && ( rand(1, 6) + rand(1, 6) ) % 2 == 0 ) || ( $bet == 'odd' && ( rand(1, 6) + rand(1, 6) ) % 2 != 0 ) ) { echo '<p>You win!</p>'; } else { echo '<p>You lose!</p>'; }
output_paragraph
, which takes in a string
of text and echoes it within an HTML paragraph element
bakuchi.php
to use this functionoutput_paragraph
function: if the value passed to it
is the empty string, then it shouldn't output anything
output_section
, which echoes a
section
containing a heading and some content
void output_section( string $id, int $level, string $heading, string $content )where
$id
is the value of the section
's
id
attribute
$level
is the heading level we want (1-6)
$heading
is the content of the heading element
$content
is the rest of the content of the section
output_section
output_section('intro', 2, 'Introduction', '<p>Happy talk, keep talking happy talk.</p>');
<section id="intro"> <h2>Introduction</h2> <p>Happy talk, keep talking happy talk.</p> </section>
get_larger
, which takes in two
numbers and uses a two-armed conditional to return the larger of the two
if
max