I'm having some trouble with the following piece of code:
I would like to be able to view the contents of $prisonlist in the console
I would like to be able to view the contents of $prisonlist (or $prisonlist[some value]) in the console, and to display it in the text of the div.
Essentially, whenever I do, it comes up with an error known as "undefined" - although my other functions that work with it seem to work just fine (such as the //
Code:
$counter = 0;
var $prisonlist=[];
$prisonlist[0]=1;
$('#entered').text($prisonlist[0]);
$('#s1').click(function(){
$(this).toggleClass('on off');
$counter = $counter + 1;
$('#clicks').text($counter);
$prisn = Math.ceil(Math.random()*10);
$('#prisoners').text($prisn);
$boo=$prisonlist.indexOf($prisn) //finds in array whether there is any
if ($boo==-1){
$prisonlist.push($prisn); // lists the individual inside
}
});
$prisonlistouside of its scope?$prisonlist[0]which is defined there. It will display in the text if I make it change the text, but I can't view the full array when various values have been pushed into it.var $prisonlistis defined in. Is it local to a function, is it in a loop or is it in the global scope?