How do I add a new Array to the below script (linked to html, view source to see script) so that there is more than one character. As you can see, when I use the normal method (var snowletter=new Array("a","b","c") it doesn't show up correctly. What else do I have to do to separate these characters?
http://pages.prodigy.net/bluebutterfly/Snowflakes.htm
Please click on the link I provided above. You will see "a,b,c" floating around. What I want to do is to be able to have all those characters only separated, not right next to each other on the same line, and without the commas.
a
b
c
http://pages.prodigy.net/bluebutterfly/Snowflakes.htm
Please click on the link I provided above. You will see "a,b,c" floating around. What I want to do is to be able to have all those characters only separated, not right next to each other on the same line, and without the commas.
a
b
c
The code is writing the whole array every time, not just one character of it. Look at line 122 where it says "document.write..." Near the end of the line, replace
snowletter
with
snowletter[Math.floor (Math.random()* snowletter.length)]
This will randomly select one element from the array to write.
snowletter
with
snowletter[Math.floor (Math.random()* snowletter.length)]
This will randomly select one element from the array to write.
The array is being created correctly. Its how its being read that is the problem. The code assumes the variable snowflake is just a simple string, so your array is being coerced into a string which is why its displaying
'a,b,c'.
If you are trying to get three different types of snowflake, one for each letter, then you need to be changing these lines at the bottom of the script:
for (i=0;i<=snowmax;i++) {
document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
}
instead of creating a span with the entire array of snowletter, just select one letter from your array.
Here's an example. Replace the loop above with this:
var len = snowletter.length;
var pos = 0;
for (var i=0; i<=snowmax;i++) {
var flake = snowletter[pos];
document.write("<span id='s"+
i+
"'style='position:absolute;top:-"+
snowmaxsize+
"'>"+
flake+
"</span>");
pos++;
if (pos==len) { pos=0; }
}
And you get three type of snowflakes - one for each letter
If you are trying to get three different types of snowflake, one for each letter, then you need to be changing these lines at the bottom of the script:
for (i=0;i<=snowmax;i++) {
document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
}
instead of creating a span with the entire array of snowletter, just select one letter from your array.
Here's an example. Replace the loop above with this:
var len = snowletter.length;
var pos = 0;
for (var i=0; i<=snowmax;i++) {
var flake = snowletter[pos];
document.write("<span id='s"+
i+
"'style='position:absolute;top:-"+
snowmaxsize+
"'>"+
flake+
"</span>");
pos++;
if (pos==len) { pos=0; }
}
And you get three type of snowflakes - one for each letter
Try initializing your array using single quotes, maybe the concatenation in your for loop is causing the problem:
snowletter=new Array('a','b','c')
Or you could try:
snowletter=new Array(\"a\",\"b\",\"c\")
snowletter=new Array('a','b','c')
Or you could try:
snowletter=new Array(\"a\",\"b\",\"c\")
The code is writing the whole array every time, not just one character of it. Look at line 122 where it says "document.write..." Near the end of the line, replace
snowletter
with
snowletter[Math.floor (Math.random()* snowletter.length)]
This will randomly select one element from the array to write.
snowletter
with
snowletter[Math.floor (Math.random()* snowletter.length)]
This will randomly select one element from the array to write.
what are you trying to do?