English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

2006-08-16 05:22:04 · 4 answers · asked by Kristina 3 in Computers & Internet Programming & Design

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

2006-08-16 05:34:00 · update #1

4 answers

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.

2006-08-16 05:40:27 · answer #1 · answered by Anonymous · 0 0

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(""+snowletter+"")
}

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(""+
flake+
"
");
pos++;
if (pos==len) { pos=0; }
}


And you get three type of snowflakes - one for each letter

2006-08-16 12:38:41 · answer #2 · answered by Isofarro 3 · 0 0

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\")

2006-08-16 12:35:10 · answer #3 · answered by katie 3 · 0 0

what are you trying to do?

2006-08-16 12:27:40 · answer #4 · answered by DesignR 5 · 0 0

fedest.com, questions and answers