I have an array, gradesArray, which I'm able to see with console.log(gradesArray) within my program, but when I go to access it typing gradesArray or gradesArray.length or something similar into the (Chrome) console, I get ReferenceError: gradesArray is not defined.
Here's the jQuery I use to fill the array with Grade objects:
$(document).on('click', '#savegrades', saveGrade);
function saveGrade() { // grabbing data from a form
var studentClass = currentClass;
var studentName = currentStudent;
var dateStamp = $(this).parents('#gradingform').children('#date').val().replace(/-/g, "");
var teamwork = parseInt( $(this).parents('#gradingform').children('#teamwork').val() );
var participation = parseInt( $(this).parents('#gradingform').children('#participation').val() );
var punctuality = parseInt( $(this).parents('#gradingform').children('#punctuality').val() );
var professionalism = parseInt( $(this).parents('#gradingform').children('#professionalism').val() );
var timemanagement = parseInt( $(this).parents('#gradingform').children('#timemanagement').val() );
var newGrade = new Grade(studentClass, studentName, dateStamp, teamwork, participation, // create new Grade object from form values
punctuality, professionalism, timemanagement);
alert('class: ' + newGrade.studentClass + ', name: ' + newGrade.studentName + ', date: ' + newGrade.dateStamp + ', teamwork: ' + newGrade.teamwork + ', participation: ' + newGrade.participation + ', punctuality: ' + newGrade.punctuality + ', professionalism: ' + newGrade.professionalism + ', time management: ' + newGrade.timemanagement + ', total: ' + newGrade.total);
gradesArray.push(newGrade);
console.log(gradesArray);
}
After this code runs, that console.log(gradesArray) bit works just fine, giving me a nice array of Grade objects. But when I type gradesArray into the console, I get a reference error telling me that the variable is undefined. Also, later in the program, I try to use if (typeof gradesArray != 'undefined'), but the function doesn't fire.
What's the deal? The browser will log the array if I ask it to from the .js file, but it won't if I ask it to right from the console; and, even after I've filled it with objects, it's still undefined, even though they're showing up in the console.
Thanks in advance.
gradesArrayoriginally declared?$(document).ready(function() {...});. Must be tired. Thanks to all.