Gari Jaen
Gari Jaen

Reputation: 33

What's wrong with the array?

<html>

<head>

    <title> Random </title>

    <script type="text/javascript" language="JavaScript">

        var typeFont = new Array ( "cooper","Fixedsys","Edwardian Script ITC", "Gill Sans MT", "Kozuka Gothic Pro", "Lucida Sans", "Adobe Gothic Std", "Adobe Naskh", "Algerian","Arial Unicode MS");

        function font()
        {
            head6.style.fontFamily = typeFont[ Math.floor( Math.random * 10 ) ];
        }
    </script>
</head>

<body>

    <center>
        <h1 onmouseover="font()" onmouseout="font" id="head6" > this is the text </h1>
    </center>

</body>

I am trying to change the font every time the mouse is over or out and this function with head6.style.fontFamily = typeFont[3] but it doesn't with the array.

Upvotes: 0

Views: 92

Answers (1)

adeneo
adeneo

Reputation: 318182

You're getting NaN as Math.random is a function and it can't be parsed to a number.

You have to call the funtion

Math.floor( Math.random() * 10 ) 

Note that this is fine as long as the array have exactly 10 indices, but you'd generally want to use the arrays length instead of 10

Upvotes: 2

Related Questions