LoginSignup
0
0

More than 3 years have passed since last update.

サイコロの出目によって出力する文章を変化させる処理

Posted at

ポートフォリオ作成のためのphpでの機能実装。

出目の数が4以上の場合「スライムの攻撃をかわした」
それ以外の場合「スライムから10のダメージを受けた」を出力する。

<?php

$dice = rand(1,6);
echo "サイコロは".$dice."\n";
if($dice >= 4){
    echo "スライムの攻撃をかわした";
}elseif ($dice <= 3) {
    // code...
    echo "スライムから10のダメージを受けた";
}
?>

学習当初はif文とelseifすら理解できていなかったが、さすがに実務で学習すれば理解が定着しているように思う。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0