Question: I'm trying to create an object in javascript with PHP. This is my script:

```
    <script>
        $(document).ready(function(){
            var genres = [
    <?php
    $last = count($userGenres) - 1;
    $i = 0;
    foreach($userGenres as $a){
        $i++;
        echo '{"value":"'.$a['genre'].'", "name":"'.$a['name'].'"}';
        if($i < $last){
            echo ',';
        }
    }
    ?>
                        ];
   });
</script>

```

When I check the generated source, it creates a valid object, but the whole script in that tag doesn't work now. How would fix this, without JSON?

Thanks

Answer: 
You forgot to close the `.ready()` method and the anonymous function inside of it.

Try this:

```
<script>
    $(document).ready(function(){
        var genres = [
            <?php
            $last = count($userGenres) - 1;
            $i = 0;
            foreach($userGenres as $a)
            {
                $i++;
                echo '{"value":"'.$a['genre'].'", "name":"'.$a['name'].'"}';
                if($i < $last)
                {
                    echo ',';
                }
            }
            ?>
        ];
    });
</script>

```
Your function is not closed properly:

```
}
    }
    ?>
                        ];
}); // <--- add this
</script>

```