diff --git a/Question08-Function/Ex03.php b/Question08-Function/Ex03.php index 2896b64..c19b402 100644 --- a/Question08-Function/Ex03.php +++ b/Question08-Function/Ex03.php @@ -7,10 +7,10 @@ * * 引数で渡された内容が偶数ならtrue、奇数ならfalseを返す関数 */ -function isEvenNumber ($x) +function isEvenNumber ($recive) // ↑引数はXだが21行目の指示はnumberで呼び出すことを意味している { - $result = (($x % 2 )=== 0); + $result = (($number % 2 )=== 0); return $result; } diff --git a/Question08-Function/Ex05.php b/Question08-Function/Ex05.php index e22ace2..3ed029e 100644 --- a/Question08-Function/Ex05.php +++ b/Question08-Function/Ex05.php @@ -7,7 +7,14 @@ * * 引数で渡された横の長さ(width)と縦の長さ(height)から、四角形の面積を返す関数 */ +function quadrangle($width, $height) +{ + $result = '面積は:' . ($width * $height); + return $result; +} +$width = 20; +$height = 50; /* TODO: * 以下の仕様で関数を作成してください @@ -17,7 +24,26 @@ * * 引数で渡された横の長さ(width)と縦の長さ(height)から、三角形の面積を返す関数 */ +function triangle($width, $height) +{ + $result = '面積は:' . ($width * $height / 2); + return $result; +} + +$width = 20; +$height = 50; + - // TODO: // 変数choiceの中が、1であれば四角形の面積を算出するメソッドを、2であれば三角形の面積を算出するメソッドを呼び出してください +$choice = 1; + +if ($choice == 1) { + $area = quadrangle($width, $height); + echo "四角形の面積: {$area}\n"; +} + +if ($choice == 2) { + $area = triangle($width, $height); + echo "三角形の面積: {$area}\n"; +}