| ์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
|---|---|---|---|---|---|---|
| 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 |
- liststyleposition
- ์ ๋๋ฒ์ ์ ๋ ํฐ
- inlineblock
- wordspacing
- textshadow
- liststyletype
- borderstyle
- ํด๋์ค์ ๋ ํฐ
- ๊ทธ๋ฃน์ ๋ ํฐ
- ์์ด๋์ ๋ ํฐ
- formtag
- fontweight
- texttransform
- ๋ชจ๋์นํฐํธ
- bordercollapse
- gtammertable
- ํฐํธ์จ์ดํธ
- textdecoration
- ํผํ๊ทธ
- ๊ตฌ๊ธํฐํธ
- ํฅ์ค์ฝ๋
- liststyleimage
- ์ฃผ์
- captionside
- CDN
- ํ์ ์ ๋ ํฐ
- ์ถ์ฝ
- ๋นํ๊ทธ
- borderspacing
- selectorslevel4
- Today
- Total
็ก์
JS I/O (Input / Output) ์ ์ถ๋ ฅ ๋ณธ๋ฌธ
๐จ JS I/O (Input / Output)
I/O๋ ํ๋ก๊ทธ๋จ์ด ์ธ๋ถ์ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ๋ ๋ชจ๋ ๊ณผ์ .
๐ฃ Output (์ถ๋ ฅ)
ํ๋ก๊ทธ๋จ์ด ์ธ๋ถ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ด๊ฑฐ๋ ๋ณด์ฌ์ฃผ๋ ๊ฒ.
๐น console.log() - ๊ฐ๋ฐ์์ ์์ํ ์น๊ตฌ
console.log("์ฝ์์ ์ถ๋ ฅ๋๋ ๋ฉ์์ง์
๋๋ค.");
console.log(10 + 20); // 30
- ๋ธ๋ผ์ฐ์ ์ ๊ฐ๋ฐ์ ๋๊ตฌ(F12) ์ฝ์(Console)์ ๋ด์ฉ์ ์ถ๋ ฅํ๋ค.
- ์ฌ์ฉ์ ํ๋ฉด์๋ ๋ณด์ด์ง ์์ผ๋ฉฐ, ์ฃผ๋ก ์ฝ๋๊ฐ ์ ์์ ์ผ๋ก ๋์ํ๋์ง ํ์ธํ๋ ๋๋ฒ๊น (Debugging) ์ฉ๋๋ก ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋ค.
๐น alert() - ๊ฒฝ๊ณ ์ฐฝ ๋์ฐ๊ธฐ
alert("ํ์ํฉ๋๋ค! ๋ก๊ทธ์ธ์ด ์๋ฃ๋์์ต๋๋ค.");
- ๋ธ๋ผ์ฐ์ ์๋จ์ ์๋ฆผ์ฐฝ์ ํ์ํ๋ค.
- ์ฌ์ฉ์๊ฐ ํ์ธ ๋ฒํผ์ ๋๋ฅผ ๋๊น์ง ๋ค์ ์ฝ๋์ ์คํ์ด ์ผ์์ ์ผ๋ก ์ค๋จ๋๋ค.
- ๊ฐ๋จํ ์๋ด๋ ํ ์คํธ์ ์ฌ์ฉํ ์ ์์ง๋ง, ์ค์ ์๋น์ค์์๋ ์์ฃผ ์ฌ์ฉํ์ง ์๋๋ค.
๐น document.write() - ์น ๋ฌธ์์ ์ง์ ์ฐ๊ธฐ
document.write("์น ํ์ด์ง ํ๋ฉด์ ์ง์ ๊ธ์๋ฅผ ์๋๋ค.");
- HTML ๋ฌธ์์ ์ง์ ๋ด์ฉ์ ์ถ๋ ฅํ๋ค.
- ํ์ด์ง๊ฐ ๋ชจ๋ ๋ก๋๋ ํ ์คํ๋๋ฉด ๊ธฐ์กด ๋ฌธ์ ๋ด์ฉ์ ๋ฎ์ด์ธ ์ ์๋ค.
- ์ฃผ๋ก ํ์ต์ด๋ ํ ์คํธ ๋ชฉ์ ์ผ๋ก ์ฌ์ฉ๋๋ฉฐ, ์ค์ ์๋น์ค์์๋ ๊ฑฐ์ ์ฌ์ฉํ์ง ์๋๋ค.
๐ฃ Input (์ ๋ ฅ)
ํ๋ก๊ทธ๋จ์ด ์ธ๋ถ๋ก๋ถํฐ ๋ฐ์ดํฐ๋ฅผ ๋ฐ๋ ๊ฒ.
๐น prompt() - ํ ์คํธ ์ ๋ ฅ๋ฐ๊ธฐ
let name = prompt("์ด๋ฆ์ ์
๋ ฅํด ์ฃผ์ธ์.", "ํ๊ธธ๋");
console.log("๋น์ ์ ์ด๋ฆ์ " + name + "์ด๊ตฐ์!");
- ์ฌ์ฉ์์๊ฒ ์ ๋ ฅ ์ฐฝ์ ๋์ ๊ฐ์ ์ ๋ ฅ๋ฐ๋๋ค.
- ์ ๋ ฅ๋ ๊ฐ์ ๋ฌธ์์ด(String) ํํ๋ก ๋ฐํ๋๋ค.
- ์ฌ์ฉ์๊ฐ ์ทจ์(Cancel) ๋ฒํผ์ ๋๋ฅด๋ฉด null์ด ๋ฐํ๋๋ค.
๐น confirm() - ์ฐฌ์ฑ/๋ฐ๋ ๋ฌผ์ด๋ณด๊ธฐ
let isDelete = confirm("์ ๋ง๋ก ์ญ์ ํ์๊ฒ ์ต๋๊น?");
if (isDelete) {
console.log("์ญ์ ๋์์ต๋๋ค.");
} else {
console.log("์ทจ์๋์์ต๋๋ค.");
}
- ํ์ธ(OK) ๊ณผ ์ทจ์(Cancel) ๋ฒํผ์ด ์๋ ์ ํ ์ฐฝ์ ๋์ด๋ค.
- ํ์ธ์ ๋๋ฅด๋ฉด true
- ์ทจ์๋ฅผ ๋๋ฅด๋ฉด false
- ์ฃผ๋ก ์กฐ๊ฑด๋ฌธ(if)๊ณผ ํจ๊ป ์ฌ์ฉํ๋ค.
โโ ์ ์ถ๋ ฅ ํ์ฉ ์ ์ฃผ์์ฌํญ โโ
- ์๋ฃํ ๋ณํ: prompt()๋ก ์ ๋ ฅ๋ฐ์ ๊ฐ์ ํญ์ ๋ฌธ์์ด(String)๋ก ์ธ์๋๋ฏ๋ก, ์ซ์ ๊ณ์ฐ์ ์ํํ๋ ค๋ฉด Number(), parseInt(), parseFloat() ๋ฑ์ ์ฌ์ฉํ์ฌ ์ซ์(Number)๋ก ๋ณํํด์ผ ํ๋ค.
- ์ฌ์ฉ์ ๊ฒฝํ(UX): alert(), prompt(), confirm()์ ๋ํ์์๊ฐ ํ์๋๋ ๋์ ์ฌ์ฉ์์ ๋ค๋ฅธ ์์ ์ ๋ง๋ ๋๊ธฐ์(Synchronous) ๋ฐฉ์์ผ๋ก ๋์ํ๋ค. ๋ฐ๋ผ์ ๊ณผ๋ํ๊ฒ ์ฌ์ฉํ๋ฉด ์ฌ์ฉ์๊ฐ ๋ถํธํจ์ ๋๋ ์ ์์ผ๋ฉฐ, ์น ํ์ด์ง์ ์ฌ์ฉ์ฑ์ด ๋จ์ด์ง ์ ์๋ค.
- ํ๋์ ์ธ ๋ฐฉ์: ์ค์ ์น ์ ํ๋ฆฌ์ผ์ด์ ์์๋ alert(), prompt(), confirm() ๋์ HTML ํผ(Form) ์์์ DOM ์กฐ์์ ํ์ฉํ์ฌ ์ ์ถ๋ ฅ์ ์ฒ๋ฆฌํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง๋ค.
๐โ POINT ๐โ
โ๏ธ ์ถ๋ ฅ์ ์ฃผ๋ก ๊ฐ๋ฐ ์ค์ console.log, ์ฌ์ฉ์ ์๋ฆผ์ alert ๋ฅผ ์ฌ์ฉํ๋ค. โ๏ธ
โ๏ธ ์ ๋ ฅ์ prompt๋ก ๋ฌธ์์ด์, confirm์ผ๋ก ์ฐธ/๊ฑฐ์ง ๊ฐ์ ์ป์ ์ ์๋ค. โ๏ธ
โ๏ธ ๋ธ๋ผ์ฐ์ ๊ธฐ๋ณธ ๋ํ์์๋ ์คํ์ ์ผ์ ์ ์ง์ํจ๋ค๋ ํน์ง์ด ์๋ค. โ๏ธ
'<script>' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| HTML์์ JavaScript๋ฅผ ๋ฐฐ์นํ๋ ๊ฐ์ฅ ์ข์ ์์น (0) | 2026.05.26 |
|---|---|
| ECMAScript (ES6) (0) | 2026.05.26 |
| JS coding rule and style guide (0) | 2026.05.26 |
| console.log() (0) | 2026.05.26 |
| ์๋ฐ์คํฌ๋ฆฝํธ (JS, JavaScript) (0) | 2026.05.26 |
