In this code it is supposed to find the age of the "var dob" then loop through the array to find the grade the student would be in.
I have been told that I have the proper code to find the person's age. I also have the proper array. My problem seems to be in my while loop.
I have an error in my syntax in my while loop.
<script language="javascript" type="text/javascript">
var dob = '20120810';
var year = Number(dob.substr(0, 4));
var month = Number(dob.substr(4, 2)) - 1;
var day = Number(dob.substr(6, 2));
var today = new Date();
var age = today.getFullYear() - year;
if (today.getMonth() < month || (today.getMonth() == month && today.getDate() < day)) {
age--;
}
//document.write("You are " + (age + 1) + " Years old"+"<br>");
var grade = [
[6,'Grade 1'],
[7,'Grade 2'],
[8,'Grade 3'],
[9,'Grade 4'],
[10,'Grade 5'],
[11,'Grade 6'],
];
while (var age = 0; age < grade; age++){
document.write(grade[age]);
}
</script>
whiletofor, that looks like that.grade[i][0]- lists are zero based... And useiin your loop. w3schools.com/js/js_loop_for.asp Try thisalert(grade[0][0]);thenalert(grade[1][0]);age < grade)grade.lengthmay have been what you were after instead of grade on its own.