Start | Time | IF | Date Object | Arrays | Avoid the work | Hide email | Random | Intigrate HTML | Test
Writing HTML with JavaScript
We have already written a little HTML in previous pages by using <br> within the text to insert a line break but anything is possible.
For instance :
We could load a different graphic depending on which day it is or change the color of the page and text at random.
From the previous pages you already have that knowledge.
Here is a simple script changing the colors of a table at random
<Script Language="JavaScript">
<!--
// Choose a number between 0 and 5
choice=Math.round(Math.random()*5);
// Assign 2 variables 'bgcolor' and 'text' with different colors depending on the number of 'choice'
if (choice==0){
bgcolor='red';
text='white';
}
if (choice==1){
bgcolor='white';
text='red';
}
if (choice==2){
bgcolor='blue';
text='yellow';
}
if (choice==3){
bgcolor='yellow';
text='blue';
}
if (choice==4){
bgcolor='green';
text='lavender';
}
if (choice==5){
bgcolor='lavender';
text='green';
}
// Print out the resulting table in HTML

document.write(
'<table border="1" cellspacing="0" cellpadding="10" bgcolor="'+bgcolor+'"><tr><td ><font color='+text+'><b>Since choice came out at '+choice+'.<br> The
background is '+bgcolor+' and the text is '+text+'</b></font></td></tr></table>'
)

//-->
</Script>
Refresh the screen to see different results


Next : A little test to see how much you have learned

Home