Download presentation
Presentation is loading. Please wait.
Published bySarah Chandler Modified over 9 years ago
1
Exercise 1: IF/ELSE Step 1: Open NotePad++ and create “number.php” in your webspace Step 2: Write codes to do the following 1.Generate a random number x in [1,10] and display it Hint 1: Use rand(1,10) to generate a random number in [1,10] Hint 2: Use variable $x to store the rand number Hint 3: Use echo to output the variables 2.Determine whether x is an odd number or an even number, and display the result Hint: Use the expression $x % 2 to find the remainder of $x divided by 2. IST2101
2
Exercise 1 answer A Simple PHP Page <?php $x = rand(1,10); echo "The random number is: $x "; if ($x % 2 == 0) echo "It is an even number "; else echo "It is an odd number "; ?>
3
Exercise 2: Loop Use Loop to display “I love Penn State” in increasing font size (from 2 to 6) Font size 2 Font size 6
4
Exercise 2 answer <?php for ($i=2; $i<=6; $i++) { echo " I love Penn State! "; } ?>
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.