-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrinking.js
More file actions
85 lines (68 loc) ยท 2.73 KB
/
drinking.js
File metadata and controls
85 lines (68 loc) ยท 2.73 KB
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
// ์ถ์ฒ: ๋ณธ์ธ. uniS2
// ๋์ด๋ณ ์ฃผ๋ฅ ํ์ฉ ๋ฌธ์
/* STEP1 ----------------------------------------------------------------
function checkAge(age) {
if (age > 19) {
return true;
} else {
return confirm('์ฒญ์๋
์๊ฒ๋ ์ฃผ๋ฅ๋ฅผ ํ๋งคํ ์ ์์ต๋๋ค.');
}
}
๋ค์ ๋ฌธ์ ๋ฅผ ๋ฌผ์ํ ์ฐ์ฐ์ ? ์ OR ์ฐ์ฐ์ || ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ๊พธ์์ค. ----------------------------------------------------------------*/
// ๋ฌผ์ํ ์ฐ์ฐ์ ?๋ฅผ ์ฌ์ฉํ์ฌ ๋ณธ๋ฌธ ์์ฑํ๊ธฐ
function checkAge(age) {
return (age > 19) ? true : confirm("์ฒญ์๋
์๊ฒ๋ ์ฃผ๋ฅ๋ฅผ ํ๋งคํ ์ ์์ต๋๋ค.");
}
// OR ์ฐ์ฐ์ ||๋ฅผ ์ฌ์ฉํ์ฌ ๋ณธ๋ฌธ ์์ฑํ๊ธฐ
function checkAge2(age) {
return (age > 19) || confirm("์ฒญ์๋
์๊ฒ๋ ์ฃผ๋ฅ๋ฅผ ํ๋งคํ ์ ์์ต๋๋ค.");
}
// ์คํ๋ฐฉ๋ฒ
// ๋ณ์ age๋ prompt ๋ฉ์๋ ์ด์ฉํ๊ธฐ
// let age = prompt("๋น์ ์ ๋์ด๋ ๋ช ์ด ์
๋๊น?", "");
// checkAge(age);
// checkAge2(age);
/* STEP2 ----------------------------------------------------------------
๋์ด๊ฐ 20์ด์ธ ๊ฒฝ์ฐ์๋ '์ฑ์ธ์ด ๋ ๊ฒ์ ์ถํํฉ๋๋ค.'๋ผ๋ ๋ฌธ๊ตฌ๋ฅผ ์ถ๋ ฅํ๋ค.
๋์ด๊ฐ 19์ด ์ดํ์ธ ๊ฒฝ์ฐ์๋ '์ฒญ์๋
์๊ฒ๋ ์ฃผ๋ฅ๋ฅผ ํ๋งคํ ์ ์์ต๋๋ค.'๋ผ๋ ๊ฒฝ๊ณ ๋ฅผ ์ถ๋ ฅํ์ฌ ์ฃผ์ธ์.
----------------------------------------------------------------*/
// if ๋ฌธ ์ฌ์ฉํ๊ธฐ
function checkAge(age) {
if (age > 20) {
return true;
} else if (age === 20) {
return '์ฑ์ธ์ด ๋ ๊ฒ์ ์ถํํฉ๋๋ค.';
} else {
throw new Error('์ฒญ์๋
์๊ฒ๋ ์ฃผ๋ฅ๋ฅผ ํ๋งคํ ์ ์์ต๋๋ค.');
}
}
// ์ผํญ ์ฐ์ฐ์ ์ฌ์ฉํ๊ธฐ
function checkAge(age) {
return (age > 20) ? true
: (age === 20) ? '์ฑ์ธ์ด ๋ ๊ฒ์ ์ถํํฉ๋๋ค.' : '์ฒญ์๋
์๊ฒ๋ ์ฃผ๋ฅ๋ฅผ ํ๋งคํ ์ ์์ต๋๋ค.';
}
// ์คํ
// let age = +prompt("๋น์ ์ ๋์ด๋ ๋ช ์ด ์
๋๊น?", "");
// checkAge(age);
/* STEP3 ----------------------------------------------------------------
๋ณ์ age๋ฅผ ์ซ์๋ก ์
๋ ฅํ์ง ์์ ๊ฒฝ์ฐ ๊ฒฝ๊ณ ๋ฅผ ์ถ๋ ฅํ์ฌ ์ฃผ์ธ์.
----------------------------------------------------------------*/
function numberError(age){
if (typeof(age) != 'number') {
throw new Error('checkAge ํจ์์ ๋งค๊ฐ๋ณ์๋ ์ซ์๋ฅผ ์
๋ ฅํด์ผ ํฉ๋๋ค.');
}
// return (typeof(age) == 'number' ) || confirm('checkAge ํจ์์ ๋งค๊ฐ๋ณ์๋ ์ซ์๋ฅผ ์
๋ ฅํด์ผ ํฉ๋๋ค.');
}
function checkAge(age) {
numberError(age);
if (age > 20) {
return true;
} else if (+age === 20) {
return '์ฑ์ธ์ด ๋ ๊ฒ์ ์ถํํฉ๋๋ค.';
} else {
throw new Error('์ฒญ์๋
์๊ฒ๋ ์ฃผ๋ฅ๋ฅผ ํ๋งคํ ์ ์์ต๋๋ค.');
}
}
// ์คํ
let age = prompt("๋น์ ์ ๋์ด๋ ๋ช ์ด ์
๋๊น?", "");
checkAge(age);