Wednesday, October 8, 2014

Lab 5

In this Lab, what I managed to do was create a table with boxes all labeled with their designated #, going from numbers 1 through 9. In class we learned about If, If-else and switch statements that have to do with java script. So the way this was made was through alert boxes, but that's the JavaScript. I first made a table using tr, td and div tags. With these tags I was able to make each box equally sided and proportional along with keeping the colors consistent with black and red, which actually co reside with the background color. Within each of these boxes contains a code, for example for box 1 on the top left corner here is the code:
<td width="64" bgcolor="#000000"
<div align="center"><button id="b1">1</button></div>
</td>
the "bgcolor" determines the color of the box, if you pay attention to the div code you can see that the box is aligned to the center and a button id was added so that "b1" or button 1, which was labeled 1 in the box would be a button.

Afterwards,  I added the java script. the way I did this was by having the code correlate with one another. I made three functions, row1, swag1 and swag2. Here is an example for the code of row1 :
function row1() {
 var info=this.id;
 if(info=='b1') alert('This is using the "If" statement.');
 if(info=='b2') alert('Then "If" statement determines if something is true or false.');
 if(info=='b3') alert('You can use the "If" statement if you want to execute some code only if a specified condition is true.');
}

As you can see this is the code for an alert box. This code goes for boxes 1, 2 and 3. According to this code if I click button 1 the alert will be 'This is using the "If" statement.' The same goes for the rest of the buttons in the table.





No comments:

Post a Comment