Hi I have the code to loop through an array and display a child’s grade and age on a HTML table according to their birthdate.
I want to give this code a method but when I add in my code function determineGrade (birthDate) { } it breaks my code and it doesn’t work. where do I add this code or is this the proper code to add a method?
<!Doctype html>
<html>
<!--Header-->
<head>
<style>
td{
padding-top: 3px;
padding-bottom: 3px;
padding-right: 20px;
padding-left: 20px;
}
</style>
<title>JavaScript Assignment 4- Jasmine Lusty</title>
<!--can contain javascript imports but page javascipt should be at the bottom of the body-->
</head>
<!--Body-->
<body>
<!-- Grade Html -->
<h4>Grades!</h4>
<table>
<tbody>
<tr id="Grade 1">
<td>Grade 1</td>
<td>6</td>
</tr>
<tr id="Grade 2">
<td>Grade 2</td>
<td>7</td>
</tr>
<tr id="Grade 3">
<td>Grade 3</td>
<td>8</td>
</tr>
<tr id="Grade 4">
<td>Grade 4</td>
<td>9</td>
</tr>
<tr id="Grade 5">
<td>Grade 5</td>
<td>10</td>
</tr>
<tr id="Grade 6">
<td>Grade 6</td>
<td>11</td>
</tr>
</tbody>
</table>
<br>
<script type="text/javascript">
//Birthdate check code.
var birthDate = new Date(2011, 6, 18, 7, 33);
var today = new Date()
var yearDifference = today.getFullYear() - birthDate.getFullYear();
var gradeYears = [['Grade 1', 6], ['Grade 2', 7], ['Grade 3', 8], ['Grade 4', 9], ['Grade 5', 10], ['Grade 6', 11]];
var grade = "";
var counter = 0;
while(counter < 6 && grade == "")
{
var currentValue = gradeYears[counter];
if (currentValue[1] == yearDifference)
{
grade = currentValue[0];
}
counter += 1;
}
var gradeRow = document.getElementById(grade);
gradeRow.style.backgroundColor = "#90EE90";
</script>
<br>
</body>
</html>
This picture is what is supposed to display, and what this code does display before I add any methods.
Thank you