views:

12

answers:

1

Hi, I am new to javascript. I wrote the following function rollDice() to produce 5 random numbers and display them. I use an anchor with click event to call the function. Problem is, in Chrome it won't display, works fine in IE, in firefox the 5 values display and then the original page w/anchor appears! I am suspicious that my script tag is too general but I am really lost. Also if there is a display function that doesn't clear the screen first that would be great.

diceArray = new Array(5)

function rollDice() { var i;

for(i=0; i<5; i++) { diceArray[i]=Math.round(Math.random() * 6) % 6 + 1;

document.write(diceArray[i]); } }

when I click should display 5 rand variables

A: 

Do any errors appear in the Javascript consoles? I know that Chrome and Firefox both have them, so you should be able to see if any errors are being generated. You could also add a few alert('Hey') messages to check that it's even being launched in Chrome.

I do see that you don't have a semi-colon after your first line, but I don't know if that's a direct cut and paste, or if you typed it all in manually.

Thyamine