0% found this document useful (0 votes)
26 views1 page

!doctype HTML Head Meta Script Script Title Title Head Body P P Script

The document defines a Grades constructor function to create Grade objects with properties like id, student name, mark, and course name. It creates 5 Grade objects for a student and stores them in an array. A for loop iterates through the array, assigns a GradeId property based on the array index, and outputs the grade details to the HTML document.

Uploaded by

prateek_tater
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

!doctype HTML Head Meta Script Script Title Title Head Body P P Script

The document defines a Grades constructor function to create Grade objects with properties like id, student name, mark, and course name. It creates 5 Grade objects for a student and stores them in an array. A for loop iterates through the array, assigns a GradeId property based on the array index, and outputs the grade details to the HTML document.

Uploaded by

prateek_tater
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

<!

DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript"></script>
<title></title>
</head>
<body>
<p id="grades"></p>
<script>

// constructor function
function Grades(GradeId, StudentName, Mark, CourseName) {
this.GradeId = GradeId;
this.StudentName = StudentName;
this.Mark = Mark;
this.CourseName = CourseName;
}

var output = "";


Grades.prototype.getOutput = function () {
output += this.GradeId + " " + this.StudentName + " has got " + this.Mark + "
out of " + "100 in " + this.CourseName +"<br>";
return output;
}

var grade1 = new Grades(null, "Prateek", 87.5, "CS101");


var grade2 = new Grades(null, "Prateek", 98.5, "CS102");
var grade3 = new Grades(null, "Prateek", 56.8, "CS103");
var grade4 = new Grades(null, "Prateek", 82.5, "CS104");
var grade5 = new Grades(null, "Prateek", 79.5, "CS105");

var ArrayObj = [grade1, grade2, grade3, grade4, grade5];

for (var i = 0; i < ArrayObj.length; i++) {

ArrayObj[i].GradeId= i+1; //autogenraded index assigned to GradeId


document.getElementById("grades").innerHTML = ArrayObj[i].getOutput();
}
</script>
</body>
</html>

You might also like