ランクはどうしたいのでしょうか?
javascript
1<table id="t1">
2<tr>
3<th>生徒</th>
4<th>国語</th>
5<th>数学</th>
6<th>理科</th>
7<th>社会</th>
8<th>英語</th>
9<th>合計値</th>
10<th>ランク</th>
11</tr>
12</table>
13<script>
14class Score {
15 constructor( name, NL, math, science, society, english) {
16 this._name = name;
17 this._NL = NL;
18 this._math = math;
19 this._science = science;
20 this._society = society;
21 this._english = english;
22 this.setTable();
23 }
24 setTable(){
25 const tr=`
26 <tr>
27 <td>${this.name}</td>
28 <td>${this.NL }</td>
29 <td>${this.math}</td>
30 <td>${this.science}</td>
31 <td>${this.society}</td>
32 <td>${this.english}</td>
33 <td>${this.total}</td>
34 <td>-</td>
35 </tr>`
36 t1.insertAdjacentHTML('beforeend',tr);
37 }
38 get name() { return this._name; }
39 get NL() { return this._NL; }
40 get math() { return this._math; }
41 get science() { return this._science; }
42 get society() { return this._society; }
43 get english() { return this._english; }
44 get total() { return this._NL + this._math + this._science + this._society + this._english; }
45}
46
47const a = new Score( 'Aさん', 80, 70, 70, 50, 60);
48const b = new Score( 'Bさん', 60, 70, 40, 80, 60);
49const c = new Score( 'Cさん', 60, 70, 70, 60, 60);
50const d = new Score( 'Dさん', 80, 40, 40, 70, 70);
51const e = new Score( 'Eさん', 70, 70, 70, 60, 70);
52</script>
rank処理つき
javascript
1<table id="t1">
2<tr>
3<th>生徒</th>
4<th>国語</th>
5<th>数学</th>
6<th>理科</th>
7<th>社会</th>
8<th>英語</th>
9<th>合計値</th>
10<th>ランク</th>
11</tr>
12</table>
13<script>
14const arr=[];
15class Score {
16 constructor( name, NL, math, science, society, english) {
17 this.set('name',name);
18 this.set('NL',NL);
19 this.set('math',math);
20 this.set('science',science);
21 this.set('society',society);
22 this.set('english',english);
23 arr.push(this.total);
24 }
25 set(key,value){
26 this[`_${key}`]=value;
27 }
28 setTable(){
29 const tr=`
30 <tr>
31 <td>${this.name}</td>
32 <td>${this.NL }</td>
33 <td>${this.math}</td>
34 <td>${this.science}</td>
35 <td>${this.society}</td>
36 <td>${this.english}</td>
37 <td>${this.total}</td>
38 <td>${this.rank}</td>
39 </tr>`
40 t1.insertAdjacentHTML('beforeend',tr);
41 }
42 get name() { return this._name; }
43 get NL() { return this._NL; }
44 get math() { return this._math; }
45 get science() { return this._science; }
46 get society() { return this._society; }
47 get english() { return this._english; }
48 get total() { return this.NL + this.math + this.science + this.society + this.english; }
49 get rank() { return arr.filter(x=>x>this.total).length+1 }
50}
51
52const a = new Score( 'Aさん', 80, 70, 70, 50, 60);
53const b = new Score( 'Bさん', 60, 70, 40, 80, 70);
54const c = new Score( 'Cさん', 60, 70, 70, 60, 60);
55const d = new Score( 'Dさん', 80, 40, 40, 70, 70);
56const e = new Score( 'Eさん', 70, 70, 70, 60, 70);
57[a,b,c,d,e].forEach(x=>{
58 x.setTable();
59});
60</script>
※調整しました