A
Archos
Why I get an error about a type undefined when it has been defined in
top of function Older10() ?
===
function person(name, age) {this.name=name; this.age=age;}
function Older10(people) {
var old = people[0];
for (var index = 1; index < 10; index++) {
if (people[index] > old.age) {
old = people[index]; // ERROR! TypeError: old is undefined
}
}
return old;
}
function main() {
var array = new Array(10);
array[1] = new person("Paul", 23);
array[2] = new person("Jim", 24);
array[3] = new person("Sam", 84);
array[4] = new person("Rob", 54);
array[8] = new person("Karl", 19);
var older = Older10(array);
console.log("The older of the group is: " + older.name + "\n");
}
===
top of function Older10() ?
===
function person(name, age) {this.name=name; this.age=age;}
function Older10(people) {
var old = people[0];
for (var index = 1; index < 10; index++) {
if (people[index] > old.age) {
old = people[index]; // ERROR! TypeError: old is undefined
}
}
return old;
}
function main() {
var array = new Array(10);
array[1] = new person("Paul", 23);
array[2] = new person("Jim", 24);
array[3] = new person("Sam", 84);
array[4] = new person("Rob", 54);
array[8] = new person("Karl", 19);
var older = Older10(array);
console.log("The older of the group is: " + older.name + "\n");
}
===