Chess - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Chess.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>Exercises: Functions</title>
- <style>
- table {border: 1px solid black;}
- .white {background-color: white; width: 30px; height: 30px;}
- .black {background-color: black; width: 30px; height: 30px;}
- </style>
- </head>
- <body>
- <?php
- /**************
- * Exercise 4 *
- **************/
- echo "<h3>Exercise 4</h3>";
- // write your code here
- // un-comment the function calls once you have implemented the functions
- function odd($number){
- return $number & 1;
- }
- function chessboard(){
- echo "<table>";
- for($row = 0; $row < 8; $row++) {
- echo "<tr>";
- for($col = 0; $col < 8; $col++) {
- // even row + even column = white; odd row + odd column = white; everything else = black (if - elseif - else)
- $class = odd($row + $col) ? "white" : "black";
- echo "<td class=\"$class\"></td>";
- }
- echo "</tr>";
- }
- echo "</table>";
- }
- chessboard();
File Description
- Chess
- PHP Code
- 29 Dec-2022
- 929 Bytes
You can Share it:
Latest PHP Pastes