<!DOCTYPE HTML>
<html>
<head>
<title> 성적 출력 - 배열로 순위 </title>
<meta charset="UTF-8">
<style>
table,tr,th,td{border-collapse: collapse;border:1px solid gray;height:30px; }
table{width:1000px;}
th{background-color:#c0c0c0;}
tr:nth-child(even){background-color:#dedede;}
</style>
<script type="text/javascript">
var cnt=1; //함수 sample_data 에서 사용될 학생번호 카운터
var students = [];
var i = 1;
// "확인" 버튼 눌렀을때 호출되는 main함수
function main( sNo,name, korean, math, english, science )
{
// 입력받은 값을 Student 함수를 이용해서 배열에 넣기
students.push ( new Student( sNo,name, korean, math, english, science ) ) ;
students.sort ( function (right, left) { return left.getSum() - right.getSum(); } ); // 총점에 따라 오름차순으로 정렬
// 3등까지만
//students = students.slice(0,3);
area[removed] = makeTag(); // print함수 호출해서 area에 출력
}
// 성적 정보를 배열에 넣는 함수
function Student(sNo,name, korean, math, english, science)
{
// this => students 를 지칭함.
this.학번 = sNo;
this.이름 = name;
this.국어 = parseInt(korean);
this.수학 = parseInt(math);
this.영어 = parseInt(english);
this.과학 = parseInt(science);
// 총점
this.getSum = function (){
return this.국어 + this.수학 + this.영어 + this.과학;
};
// 평균
this.getAverage = function(){
return this.getSum() / 4;
};
}
// 출력
function makeTag()
{
var output ="";
for ( i in students ) // students 배열의 주소값이 차례로 넘어옴
{
with ( students[i] )
{
output += "<tr align=center><td>"+ ((parseInt(i)+1)) +"</td>"; // 순위
output += "<td>" + 학번+ "</td>"; // 학번
output += "<td>" + 이름 + "</td>"; // 이름
output += "<td>" + 국어 + "</td>"; // 국어 점수
output += "<td>" + 수학 + "</td>"; // 수학 점수
output += "<td>" + 영어 + "</td>"; // 영어 점수
output += "<td>" + 과학 + "</td>"; // 과학 점수
output += "<td>" + getSum() + "</td>"; // 총점
output += "<td>" + getAverage() + "</td></tr>"; // 평균
}
}
output += "</table>";
return output;
}
function sample_data()
{
var ssNo="20130"+cnt;
cnt++;
var num=Math.floor((Math.random()*100)+1);
name="길동"+num;
sub1=Math.floor((Math.random()*100)+1);
sub2=Math.floor((Math.random()*100)+1);
sub3=Math.floor((Math.random()*100)+1);
sub4=Math.floor((Math.random()*100)+1);
frm.txt_sNo.value=ssNo;
frm.txt_sNo.style.backgroundColor = "#ffff00";
frm.txt_name.value=name;
frm.txt_name.style.backgroundColor = "#ffff00";
frm.txt_kor.value=sub1;
frm.txt_kor.style.backgroundColor = "#ffff00";
frm.txt_mat.value=sub2;
frm.txt_mat.style.backgroundColor = "#ffff00";
frm.txt_eng.value=sub3;
frm.txt_eng.style.backgroundColor = "#ffff00";
frm.txt_sci.value=sub4;
frm.txt_sci.style.backgroundColor = "#ffff00";
main(ssNo,name,sub1,sub2,sub3,sub4);
}
//-->
</script>
</head>
<body>
<form name=frm>
<h1>성적처리</h1>
학번 : <input size=10 type="text" name="txt_sNo">
이름 : <input size=10 type="text" name="txt_name">
국어 : <input size=5 type="text" name="txt_kor">
수학 : <input size=5 type="text" name="txt_mat">
영어 : <input size=5 type="text" name="txt_eng">
과학 : <input size=5 type="text" name="txt_sci">
<input type="button" value="확인" txt kor.value, txt_mat.value, txt_eng.value, txt_sci.value)">
<input type="button" value="Sample Data"
<hr>
<table>
<tr align=center>
<th>순위</th>
<th>학번</th>
<th>이름</th>
<th>국어</th>
<th>수학</th>
<th>영어</th>
<th>과학</th>
<th>총점</th>
<th>평균</th>
</tr>
<tbody id="area">
</tbody>
</table>
</form>
</body>
</html>
코드 전문인데
스샷은 총점이 높은 애가 무조건 1위 자리로 이동함
sort가 그렇게 되어있슴
근데 그렇게 안하고
그냥 출력만 시키고 총점이 높던 안높던 움직이지는 않고
순위만 총점이 높은놈에게 1위로 가도록 할려면 어케해야함 ?
해결하면 거짓말안하고 5천원 안으로 기프티콘 쏘아드림
ㄹㅇ임 ㅠㅠ
시발 진짜 쫌 도와줘요
웹이라니 정말 극혐이군
아 시발 이 좆같은거 왜 배우는지 모르겠씀. 그래도 일단 아렬주세요
극혐이 맞긴한데 답변은 해 줘 시발
ㄴ 니가 자바스크립트에 대해서 뭘 안다고 베껴왔느니 뭐니 함 쓰레기새끼가 그냥 넌 꺼져있어