How do you use variables inside of click functions.
I have some vars I wanna persist beyond the click function. I declared them outside. I'm not much of a java scriptie. But as I understand you use var for local vars and you don't use var for globals. I guess these are globals.
- $(document).ready(function() {
piecesUsed = [];
piecesAvailable = ['NSW','WA','Queensland','Victoria','Tasmania','NZ','SA', 'NT'];
currentPiece = '';
$('#ask').click( function() {
if (currentPiece == '') {
i = Math.floor(Math.random() * length(piecesAvailable));
currentPiece = piecesAvailable[i];
}
playTrack('http://localhost/GeoP-Test/audio/' + currentPiece + '.mp3');
});
//more jquery stuff
});
When I go into the Firebug debugger everything goes to hell when it gets to the Math line. I can't even get the Error console to see if there's something wrong. Pls tell me what I'm doing wrong here. Thanks!