1+ // let students =[
2+ // {
3+ // regno:1001,
4+ // name:"Krish",
5+ // marks:[95,55,65,80,75],
6+ // total:function(){
7+ // return this.marks.reduce((a,b)=>a+b);
8+ // },
9+ // max: function(){
10+ // return this.marks.reduce((a,b)=>a>b?a:b);
11+ // }
12+
13+ // },
14+ // {
15+ // regno:1002,
16+ // name:"Rajesh",
17+ // marks:[45,55,65,80,75],
18+ // total:function(){
19+ // return this.marks.reduce((a,b)=>a+b);
20+ // },
21+ // max: function(){
22+ // return this.marks.reduce((a,b)=>a>b?a:b);
23+ // }
24+ // },
25+ // {
26+ // regno:1003,
27+ // name:"Charan",
28+ // marks:[55,45,65,80,75],
29+ // total:function(){
30+ // return this.marks.reduce((a,b)=>a+b);
31+ // },
32+ // max: function(){
33+ // return this.marks.reduce((a,b)=>a>b?a:b);
34+ // }
35+ // }
36+
37+ // ]
38+
39+ class Student {
40+
41+ constructor ( regno , name , marks ) {
42+ this . regno = regno ;
43+ this . name = name ;
44+ this . marks = marks ;
45+ }
46+ toString ( ) {
47+ return `Regno: ${ this . regno } `
48+ }
49+ total ( ) {
50+ return this . marks . reduce ( ( a , b ) => a + b ) ;
51+ }
52+ }
53+
54+ students = [ new Student ( 1001 , 'Krish' , [ 95 , 55 , 65 , 80 , 75 ] ) ,
55+ new Student ( 1006 , 'Manoj' , [ 75 , 55 , 65 , 80 , 75 ] ) ,
56+ new Student ( 1005 , 'Rajesh' , [ 65 , 55 , 65 , 80 , 75 ] ) ,
57+ new Student ( 1004 , 'Jayesh' , [ 55 , 55 , 65 , 80 , 75 ] ) ] ;
58+
59+
60+ html = '' ;
61+ if ( students . length > 0 ) {
62+ showTable = document . querySelector ( "#showTable" ) ;
63+
64+ html += "<table class='table table-hover'>" ;
65+ html += "<thead><tr><th>Regno</th><th>Name</th><th>Total</th></tr>" ;
66+ html += "<tbody>" ;
67+
68+ students . forEach ( s => {
69+ html += `<tr><td>${ s [ 'regno' ] } </td><td>${ s [ 'name' ] } </td><td>${ s . total ( ) } </td></tr>` ;
70+ } )
71+ html += "</tbody></table>" ;
72+ } else {
73+ html = 'There are no students'
74+ }
75+ showTable . innerHTML = html ;
0 commit comments