Click to See Complete Forum and Search --> : For Loops
vfreese
03-25-2003, 07:47 PM
I need some help developing a three nested For loop, using this structure:
for (i = 0; i<= 5; i++) {
for (j = 0; j <= 5; j++) {
for (k = 0; <= 5; k++) {
}
}
}
this needs to have tables and rows as well.
with in the innermost For loop, write table cells that have background color = to color value, #color[i]color[j]color[k]
with in the middle loop write tags to start and end table row.
with in the outer loop, write tags to create and close the table.
I have been trying to figure this out for days..can anyone show me some insite?
I will work on it and see what I can come up with.
vfreese
03-25-2003, 08:08 PM
Thanks for taking a look..I have been trying to teach myself this Java Script language and this is suppose to create a color palatte..I have the Array all complete..I have one table complete, but it is suppose to generate 216 colors..
Again,,thank you for giving it a shot..I appreciate it
Could you try to post your whole script? Because I don't 100% get what you mean... I thought about it for a minute, and realized that with the 3 for loops you gave me, I'm not sure what you want. And I don't really want to make this big ol' script for nothing...
dabush
03-25-2003, 10:22 PM
the background colors wont work. a color code needs 6 digits; your example only gives 3
vfreese
03-26-2003, 05:14 AM
I have created an Array using the following:
<script language="JavaScript">
<!--Hide from non-JavaScript browsers
function Colors (colorNumber) {
var Colors=new Array('00','33','66','99','CC','FF');
Color[1]="00";
Color[2]="33";
Color[3]="66";
Color[4]="99";
Color[5]="CC";
Color[6]="FF"'
return Color[ColorNumber};
}
//Stop hiding
</script>
dabush
03-26-2003, 07:09 AM
what was that?
vfreese
03-26-2003, 11:18 AM
This is an ordered collection of values referenced by a single varible name.
An Array object is used to store a set of values in a single variable name. Each value is an element of the array and has an associated index number.
var variable =new Array (size);
var Colors=new Array('00','33','66','99','CC','FF') ;
Colors is the name of the Array variable
Size is the number of elements in the Array.
dabush
03-26-2003, 12:00 PM
i know what an array is thank you very much. but you have a lot of learning to do about them. in the first line you state the values of the array. and then you try to repeate them in the subsequent lines. and in the subsequent, you start with index 1 instead of 0.
JimJamJammin
03-26-2003, 12:24 PM
Make sure that your 'for' loops go up to 16.
Then in the loop convert numbers 10 or above to their equivalent letters.
For example:
if(x==12)color="CO"
if(x==13)color="DO"
etc.
I'm not sure how you would display all the colours on the screen, since you're dealing with 3 dimensions, not the basic 2!
If you were dealing with just Red and Green, but not Blue, then you might display all the colours in the following way:
------------------------------------------
var red=""
var green=""
var blue="00" // I'm not using blue in this example
for(var i=0; i<=16; i++){
document.write("<tr height=10>")
for(var j=0; j<=16; j++){
if(i==10)red="A"
if(i==11)red="B"
etc.
if(j==10)green="A"
if(j==11)green="B"
etc.
red+="0" // make the colour 2 digits
green+="0"
document.write("<td width=10 bgcolor=#"+red+green+blue+">")
}
document.write("</tr>")
}
--------------------------------------
There might be fundamentally wrong with code because I didn't test it and I was in a rush, but you should get the idea.
Telling the administrator what an 'array' is, that's a classic! ;)
havik
03-26-2003, 12:25 PM
This script writes a table, but it uses only 2 for loops. Not exactly what you want but you could alter it to work maybe?
var rows=3;
var cols=3;
function writeTable() {
document.write('<table cellspacing=5 cellpadding=5 border=1 bordercolor="black">');
for(var r = 0; r < rows; r++) {
document.write('<tr>');
for(var c = 0; c < cols; c++) {
document.write('<td width=5 height=5>test</td>');
}
document.write('</tr>');
}
document.write('</table>');
}
havik
dabush
03-26-2003, 12:39 PM
this is thebasis that you will use to make it.
<script language=JavaScript type=text/javascript>
<!--
var str = '';
for (i=0;i<=5;i++)
{
str+="<table>";
for (j=0;j<=5;j++)
{
str+="<tr>";
for (k=0;k<=5;k++)
{
str+="<td> </td>
}
str+="</tr>";
}
str+="</table>";
}
// -->
</script>
vfreese
03-26-2003, 01:36 PM
Dabush,,,,sorry if you felt offended by my post, however,,I am a beginner and I am an individual that enjoys learning..so, your comment about me having alot to learn,,your exactly correct,,and I am open to criticism, that is how I learn,,it can only be positive..:-)
dabush
03-26-2003, 04:12 PM
sorry, if i came off a bit rude. i'm having a ****ty day