-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice9-2.html
More file actions
56 lines (47 loc) · 1.88 KB
/
practice9-2.html
File metadata and controls
56 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>나은민-3</title>
</head>
<body>
<p>Q. 웹프로그래밍의 3가지 요소는?</p>
<input type="button" value="답 보기" onclick="showAnswer('web')" />
<input type="button" value="답 삭제" onclick="removeAnswer('web')" />
<div id="answer-web"></div>
<!-- 답변을 표시할 div -->
<p>Q. 클라우드 컴퓨팅이란?</p>
<input type="button" value="답 보기" onclick="showAnswer('cloud')" />
<input type="button" value="답 삭제" onclick="removeAnswer('cloud')" />
<div id="answer-cloud"></div>
<!-- 답변을 표시할 div -->
<script>
function showAnswer(question) {
const answerDiv = document.getElementById('answer-' + question);
// 답변이 이미 존재하는지 확인
if (answerDiv.childElementCount > 0) {
return; // 이미 답변이 존재하면 함수 종료
}
let answerText;
if (question === 'web') {
answerText = 'HTML, CSS, JavaScript';
} else if (question === 'cloud') {
answerText = '컴퓨팅 자원을 인터넷을 이용하여 사용하는 것';
}
// 답변을 표시할 div 요소 생성
const answerParagraph = document.createElement('p');
answerParagraph.textContent = answerText;
// 해당 질문의 답변 div에 추가
answerDiv.appendChild(answerParagraph);
}
function removeAnswer(question) {
const answerDiv = document.getElementById('answer-' + question);
// 답변이 있는 경우에만 삭제
while (answerDiv.firstChild) {
answerDiv.removeChild(answerDiv.firstChild);
}
}
</script>
</body>
</html>