본문 바로가기
HTML│CSS│Java Script

html 예제

by 자유코딩 2017. 12. 6.

html 예제

 

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
    document.write("<h2> Math Method </h2>");
    document.write("2의 10승 : "+Math.pow(2,10)+"<br/>");
    document.write("3,25,9,47,2,5,7 중 가장 큰 수 : "+Math.max(3,25,9,47,2,5,7)+"<br/>");
    document.write("3,25,9,47,2,5,7 중 가장 작은 수 : "+Math.min(3,25,9,47,2,5,7)+"<br/>");
    //ceil() 올림 , round() 반올림, floor() 버림
    document.write("<hr/>");
    
    document.write("3.44 반올림 : "+Math.round(3.44)+"<br/>");
    document.write("3.45 반올림 : "+Math.round(3.45)+"<br/>");
    document.write("3.54 반올림 : "+Math.round(3.54)+"<br/>");
    document.write("3.55 반올림 : "+Math.round(3.55)+"<br/>");
    document.write("<hr/>");
    
    document.write("3.44 올림 : "+Math.ceil(3.44)+"<br/>");
    document.write("3.45 올림 : "+Math.ceil(3.45)+"<br/>");
    document.write("3.54 올림 : "+Math.ceil(3.54)+"<br/>");
    document.write("3.55 올림 : "+Math.ceil(3.55)+"<br/>");
    document.write("<hr/>");
 
    document.write("3.44 버림 : "+Math.floor(3.44)+"<br/>");
    document.write("3.45 버림 : "+Math.floor(3.45)+"<br/>");
    document.write("3.54 버림 : "+Math.floor(3.54)+"<br/>");
    document.write("3.55 버림 : "+Math.floor(3.55)+"<br/>");
    document.write("<hr/>");
 
    document.write("3.44 : "+parseInt(3.44)+"<br/>");
    document.write("3.55 : "+parseInt(3.55)+"<br/>");
    document.write("<hr/>");
    
    document.write("랜덤 : "+Math.random()+"<br/>");
    document.write("랜덤 : "+parseInt(Math.random()*3)+"<br/>");
    document.write("<hr/>");
    
    document.write("<h2> String Methods </h2>");
    var str="Please locate where 'locate' occurs";
    document.write("문자열 : "+str+"<br/>");
    document.write("문자열의 길이 length : "+str.length+"<br/>");
    document.write("한 글자 추출 charAt : "+str.charAt(5)+"<br/>");
    document.write("글자 위치 값 얻기 indexOf : "+str.indexOf("e")+"<br/>");
    document.write("<hr/>");
    
    str = "Apple,Banana,Kiwi";
    //slice(시작위치 , 끝위치) 끝위치는 포함 안됨, //음수는 끝부터 시작
    document.write("글자 : "+str+"<br/>");
    document.write("글자 나누기 : "+str.slice(7,13)+"<br/>");
    document.write("글자 나누기 : "+str.slice(-12,-6)+"<br/>");
    //substring=slice
    document.write("글자 나누기 slice : "+str.slice(7,13)+"<br/>");
    //substr(시작위치 , 개수)
    document.write("글자 나누기 substr : "+str.substr(7,13)+"<br/>");
    document.write("<hr/>");
    
    //split 배열로 저장하기
    var arr=str.split(",");
    for ( var k in arr) {
        document.write(arr[k]+"<br/>");
    }
    document.write("<hr/>");
    //글자 변경 : replace("기존 문자열","변경할 문자");
    str= str.replace("Banana","Orange");
    document.write(str);
    document.write("<hr/>");
    
    //대소문자 변경 , toLowerCase(), toUpperCase();
    str = str.toUpperCase();
    document.write(str+"<br/>");
    
    str = str.toLowerCase();
    document.write(str+"<br/>");
    
</script>
</head>
<body>
 
</body>
</html>
cs

 

출력 화면 

 

'HTML│CSS│Java Script' 카테고리의 다른 글

html 경고창 , 현재 시간 출력 예제  (0) 2017.12.06
html 예제  (0) 2017.12.06
p 태그 id에 자바스크립트 결과 담기  (0) 2017.12.06
html 전구 켜고 끄기  (0) 2017.12.06
html 표 추가 삭제  (0) 2017.12.06

댓글