-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
99 lines (84 loc) · 3.66 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>프로젝트</title>
<style>
.menu{
display: flex;
}
.ball{
width: 10rem;
height: 10rem;
margin: 1rem;
border-radius: 50%;
/* 컨텐츠 중앙, 수직 정렬*/
text-align: center;
line-height: 10rem;
/* 폰트 정리 */
color: white;
font-size: xx-large;
font-weight: bold;
}
.balls-list{
display: flex;
flex-direction: column;
}
.ball-container{
display: flex;
}
</style>
</head>
<body>
<h1>로또 추첨 번호</h1>
<!-- 번호 입력 + 버튼 -->
<div class="menu">
<input id="input-box" type="text" placeholder ="원하는 로또 번호 개수 입력" onfocus="this.placeholder=''">
<button id="lotto-btn" type="submit">클릭</button>
</div>
<!-- 로또번호 출력 -->
<div id="result" class="balls-list"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
<script>
const button = document.querySelector('#lotto-btn')
button.addEventListener('click', function() {
// '확인' 클릭시 처음에는 초기화
const result = document.querySelector('#result')
removeAllchild(result);
// 입력받은 숫자 가져오기
var inputNumber = document.querySelector('#input-box').value
inputNumber = parseInt(inputNumber)
// 입력받은 숫자 만큼 반복
for(i = 1; i <= inputNumber; ++i){
// 요소 만들기
const ballContainer = document.createElement('div')
ballContainer.classList.add('ball-container')
// 공을 만들어서 => 6개 만들어서
const numbers = _.sortBy(_.sampleSize(_.range(1,46), 6))
for(j = 0; j < numbers.length; ++j){
const ball = document.createElement('div')
ball.classList.add('ball')
ball.innerText = numbers[j]
if((numbers[j] >= 1) && (numbers[j] <= 10)){ball.style.backgroundColor = 'yellow'}
else if((numbers[j] >= 11) && (numbers[j] <= 20)){ball.style.backgroundColor = 'blue'}
else if((numbers[j] >= 21) && (numbers[j] <= 30)){ball.style.backgroundColor = 'red'}
else if((numbers[j] >= 31) && (numbers[j] <= 40)){ball.style.backgroundColor = 'gray'}
else if((numbers[j] >= 41) && (numbers[j] <= 46)){ball.style.backgroundColor = 'green'}
//컨테이너에 붙인다.
ballContainer.appendChild(ball)
}
// 컨테이너를 결과 영역에 붙인다.
const result = document.querySelector('#result')
result.appendChild(ballContainer)
}})
// 자식요소들 삭제하는 함수
function removeAllchild(div) {
while (div.hasChildNodes()) {
div.removeChild(div.firstChild);
}
}
</script>
</body>
</html>