I have this function
function getStudents() {
var students = [];
students[0] = {name: "Anna", mark: 65, sex: "female"};
students[1] = {name: "James", mark:33, sex: "male"};
students[2] = {name: "William", mark: 87, sex: "male"};
students[3] = {name: "Jane", mark: 72, sex: "female"};
students[4] = {name: "Rikki", mark: 60, sex: "male"};
students[5] = {name: "Angela", mark: 58, sex: "female"};
}
And then in the body i try to do this:
var students = getStudents();
var referrals = ["James", "Angela"];
for(var i = 0; i < students.length; i++){
var pTag ="<p>";
However, as soon as I try to go through the loop it tells me that it cannot do .length of an undefined variable, but I thought I already defined it by calling the function and assigning it to a variable?
var students = []in the function has no effect on the outer world. That var exists only within the function.