-
HTML5 + CSS3 + JavaScript로 배우는 웹프로그래밍 기초 9강 연습문제 답코딩/HTML5 2018. 6. 13. 19:40반응형
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script>
// CHAPTER 09 연습문제
//4번
var result = 0; var runningTime;
var time1; var time2;
time1 = new Date();
for (var i = 0; i <= 1000000; i++)
result += i;
time2 = new Date();
runningTime = time2 - time1;
document.write("<h2> 답은: " + result + "</h2><br>");
document.write("<h2>" + runningTime + "밀리초가 걸렸음! </h2>");
//5번
function strCap(string) {
var result = string.charAt(0).toUpperCase();
result = string.replace(string.charAt(0), result);
document.write(result);
}
strCap("hong");
// 6번
var month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Set', 'Oct', 'Nov', 'Dec'];
today = new Date();
document.write("<h2> It Is " + month[today.getMonth()] + "</h2>");
//7번
var movies = ["터미네이터", "트랜스포머"];
movies.push ("맨오브스틸");
movies[movies.length - 2] = "스파이더맨";
for (i = 0; i < movies.length; i++)
document.write (movies[i] + " ");
alert(movies[movies.length - 1]);
//8번
var arr = ["사과", "오렌지", "귤", "당근", "케일"];
var number = Math.random() * 5;
number = Math.floor(number);
alert(arr[number]);
//9번
function find(ar, va) {
document.write("<br>" + ar.indexOf(va));
}
arr = ["Hello", 10, 32.6, true];
find(arr, "Hello");
//10번
function check(str) {
var result = str.search("XXX");
if (result == -1)
result = false;
else
result = true;
document.write("<br>" + result + "<br>");
}
var string = prompt("검출할 문장을 적으시오.", "");
check(string);
//11번
function time() {
var today = new Date();
var now = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
document.getElementById("time").value = now;
setTimeout("time()", 1000);
}
</script>
</head>
<body>
<label for="time">현재시간: </label>
<input type="text" id="time" size="30">
<input type="button" onclick="time();">
</body>
</html>
마지막 11번은 화면이 바뀌는 것을 보기 위해 내 마음대로 문제를 살짝 바꿈
반응형'코딩 > HTML5' 카테고리의 다른 글
HTML5 + CSS3 + JavaScript로 배우는 웹프로그래밍 기초 10강 연습문제 답 (0) 2018.06.13 HTML5 + CSS3 + JavaScript로 배우는 웹프로그래밍 기초 8강 연습문제 답 (0) 2018.06.13 윈도우 오픈 (0) 2018.06.06 노드 제거 (0) 2018.06.06 노드 추가 (0) 2018.06.06