-
글쓴이글
-
2022년 3월 14일 16:03 #29468

우효창참가자<body>
<form class="ab">
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">성적 입력 및 결과 조회</label>
<div class="boxflex">
<input class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
<input class="form-control" id="exampleInputEmail11" aria-describedby="emailHelp">
</div>
<div id="emailHelp" class="form-text">We'll never share your score with anyone else.</div>
<button class="btn">조회하기</button>
</div>
</form><script>
document.getElementsByClassName("btn").addEventListener("click", function (){
console.log('gi');
})
</script></body>
의도한 바는 조회하기를 누르면 두 input박스에서 각각의 점수를 받아 합계를 alert 하는것인데
함수가 아니라고 에러가 뜨네요 ㅠㅠ
console.log는 눌렀을때 작동이 되는지를 보려고 써놨습니다.
도와주세요
2022년 3월 14일 16:50 #29472
우효창참가자getElementsByClassName("btn")에 [0]을 붙이지 않아서인걸 알았습니다!
<form class="ab">
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">성적 입력 및 결과 조회</label>
<div class="boxflex">
<input class="form-control" id="aa" aria-describedby="emailHelp">
<input class="form-control" id="bb" aria-describedby="emailHelp">
</div>
<div id="emailHelp" class="form-text">We'll never share your score with anyone else.</div>
<button class="btn">조회하기</button>
</div>
</form><script>
document.getElementsByClassName('btn')[0].addEventListener('click', function(){
var Ascore = parseInt(document.getElementById('aa').value);
var Bscore = parseInt(document.getElementById('bb').value);
var ABsum = parseInt(Ascore + Bscore);
var vAvg = Math.round(ABsum/2);
if(Ascore >= 40 && Bscore >= 40 && vAvg >=60)
alert("합격");
else if (vAvg >=60)
alert("과락");
else
alert("불합격");
})
</script>과제의 최종결과물인데 피드백 가능할까요?
-
글쓴이글
- 답변은 로그인 후 가능합니다.
