-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
185 lines (157 loc) · 4.35 KB
/
app.js
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const pointScale = ['매우 나쁨🤬', '나쁨😑', '보통🙂', '좋음😉', '매우 좋음🥳'];
const names = [
'ㅇㅈㅎ',
'ㄱㄱㅇ',
'ㄱㄴㅎ',
'ㄱㅁㅅ',
'ㄱㅇㅇ',
'ㄱㅈㅊ',
'ㄱㅈㄱ',
'ㄱㅌㅎ',
'ㄴㄱㄹ',
'ㅁㅈㅎ',
'ㅂㅅㅈ',
'ㅂㅇㅎ',
'ㅂㅈㅎ',
'ㅅㅇㅅ',
'ㅅㅅㅁ',
'ㅇㅅㅇ',
'ㅇㅅㅁ',
'ㅇㅇㅎ',
'ㅇㅈㅇ',
'ㅇㄱㅈ',
'ㅇㄱㄹ',
'ㅇㅇㅈ',
'ㅇㅈㅊ',
'ㅇㄷㅂ',
'ㅇㅅㅅ',
'ㅈㅁㅎ',
'ㅈㅇㅈ',
'ㅊㅈㅁ',
'ㅎㅎㅈ',
'ㅇㅇㅅ',
];
const result = document.getElementById('result');
const luckyColor = document.getElementById('luckyColor');
const color = document.getElementById('color');
const colorName = document.getElementById('colorName');
const emoji = document.getElementById('emoji');
const moneyButton = document.getElementById('money-button');
const successButton = document.getElementById('success-button');
const loveButton = document.getElementById('love-button');
const buttonList = [moneyButton, successButton, loveButton];
const fortuneResult = document.getElementById('fortune-result');
const luckyText = document.getElementById('lucky-text');
const luckyName = document.getElementById('lucky-name');
const buttons = document.getElementById('buttons');
const dbtn = document.getElementById('destroy');
const fact = document.getElementById('fact');
const top2 = document.getElementById('top');
const middle = document.getElementById('middle');
function randomColorSelector() {
const colorCode = [
'white',
'black',
'gray',
'red',
'orange',
'yellow',
'green',
'blue',
'navy',
'purple',
'violet',
'olive',
'skyblue',
'lime',
'beige',
'brown',
'ivory',
'khaki',
'pink',
];
const randomColor = Math.floor(Math.random() * colorCode.length);
return colorCode[randomColor];
}
const getFortunePoint = () => {
return Math.floor(Math.random() * 100);
};
const fortunePointToText = (point) => {
if (point < 10) {
return pointScale[0];
} else if (point < 30) {
return pointScale[1];
} else if (point < 70) {
return pointScale[2];
} else if (point < 90) {
return pointScale[3];
} else {
return pointScale[4];
}
};
const getLuckyName = () => {
console.log(names.length);
return names[Math.floor(Math.random() * names.length)];
};
const setFortuneResult = (target) => {
const fortunePoint = getFortunePoint();
let fortuneText = fortunePointToText(fortunePoint);
if (target === 'money-button') {
fortuneText = `재물운 ${fortuneText}`;
} else if (target === 'success-button') {
fortuneText = `성공운 ${fortuneText}`;
} else {
fortuneText = `애정운 ${fortuneText}`;
}
fortuneResult.innerText = fortuneText;
};
const setLuckyPerson = () => {
luckyText.innerText = '오늘의 은인';
luckyName.innerText = getLuckyName();
};
const setLuckyColor = () => {
const colorValue = randomColorSelector();
color.style.backgroundColor = colorValue;
colorName.innerText = colorValue.toUpperCase();
result.style.display = 'flex';
luckyColor.style.width = 'fit-content';
};
const changeButtons = (target) => {
const others = buttonList.filter((button) => button.id !== target);
others.forEach((otherButton) => {
otherButton.style.display = 'none';
});
buttonList.forEach((button) => {
button.disabled = true;
});
buttons.style.justifyContent = 'center';
dbtn.style.display = 'flex';
};
const buttonClickHandler = (event) => {
const target = event.currentTarget.id;
setFortuneResult(target);
setLuckyPerson();
setLuckyColor();
changeButtons(target);
};
moneyButton.addEventListener('click', buttonClickHandler);
successButton.addEventListener('click', buttonClickHandler);
loveButton.addEventListener('click', buttonClickHandler);
const emojiMouseEnterHandler = () => {
emoji.innerText = '✌';
};
const emojiMouseLeaveHandler = () => {
emoji.innerText = '🤞';
};
emoji.addEventListener('mouseenter', emojiMouseEnterHandler);
emoji.addEventListener('mouseleave', emojiMouseLeaveHandler);
/**
* 마지막 버튼을 눌렀을 때 정해진 문구를 제외한 나머지 none처리 함수
*/
const reset = () => {
fact.style.display = 'inline-block';
dbtn.style.display = 'none';
top2.style.display = 'none';
middle.style.display = 'none';
};
dbtn.addEventListener('click', reset);