멋사10기

[일단만드는자바스크립트] 로또 번호 추첨기

밀루루 2022. 5. 11. 00:44

실행결과

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
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>로또 번호 추첨기</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <h1>로또 번호 추첨기</h1>
    <script>
        var lotto = [];
        while (lotto.length < 6) {
            var num = parseInt(Math.random() * 45 + 1); //1~46
            if (lotto.indexOf(num) == -1) { //중복되는지 검사
                lotto.push(num);
            }
        }
        lotto.sort((a,b)=>a-b); //오름차순으로 정렬
        document.write("<div class='ball ball1'>" + lotto[0+ "</div>");
        document.write("<div class='ball ball2'>" + lotto[1+ "</div>");
        document.write("<div class='ball ball3'>" + lotto[2+ "</div>");
        document.write("<div class='ball ball4'>" + lotto[3+ "</div>");
        document.write("<div class='ball ball5'>" + lotto[4+ "</div>");
        document.write("<div class='ball ball6'>" + lotto[5+ "</div>");
    </script>
</body>
</html>
cs
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
.ball {
    float: left;
    width: 60px;
    height: 60px;
    line-height: 60px;
    font-size: 28px;
    border-radius: 100%;
    text-align: center;
    vertical-align: middle;
    color: #fff;
    font-weight: 500;
    text-shadow: 0px 0px 3px rgba(73, 57, 0, .8);
    margin-right: 6px;
}
 
.ball1 {
    background: #fbc400;
}
.ball2 {
    background: #69c8f2;
}
.ball3 {
    background: #ff7272;
}
.ball4 {
    background: #aaa;
}
.ball5 {
    background: #b0d840;
}
.ball6 {
    background: #c7c7c7;
}
cs