Checkerboard Hint

Stuck….in the 7th circle?

Take a minute to think about this problem before you just start coding it. Think of what you have learned and what can be used to solve this problem.

You’ll need these skills:

  • HTML: to create the basic web page
  • HTML: how do you create a basic grid of information??? Think…tables! Go review.
  • CSS: to create the pattern…do you remember how we created boxes back in this homework?
  • PHP: we just learned about loops – go review nested loops again!

Those are all your tools. What next? Do some pseudo code or simply write down a basic structure.

What’s a checkerboard made of? 8 rows and 8 columns.

You know that to create a table like this you’ll need this HTML structure:

<table>
  <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</table>

So, how would you do that with PHP? Notice a pattern..are there 8 columns inside of each row? And 8 rows total. So, if you loop through all the rows in the table and inside each row…loop through 8 columns…think about this one. If still stuck look here.

Also, if you want to test if things are even or odd…there is a math operator in PHP called Modulus which is used with the % operator. This returns whatever the remainder is one number divided by another. Here are some examples:

  $x = 10;
  $a = 2;
  $b = 3;
  $c = 4;
  
  echo "$x % $a is 0";
  echo "$x % $b is 1";
  echo "$x % $c is 2";

 

Finally, to get the color…just like you can echo HTML with PHP – you can also echo CSS like

echo "<p class='first'>";