๋ฐ˜๊ฐ€์›Œ์š”! ํ—ˆ๋ธŒ์ž…๋‹ˆ๋‹ค!

์ €๋Š” ๊ฐœ๋ฐœ์ž๋ฅผ ํ˜„๋Œ€ ์—ฐ๊ธˆ์ˆ ์‚ฌ๋ผ๊ณ  ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ์„ ๊ณต๋ถ€ํ•˜๋ฉฐ ๋Š๋‚€ ์ ๋“ค๊ณผ ์ด์•ผ๊ธฐ๋ฅผ ๊ธฐ๋กํ•˜๋Š” ๊ณต๊ฐ„์ž…๋‹ˆ๋‹ค.

๋„ค์ด๋ฒ„ ๋ถ€์ŠคํŠธ์ฝ”์Šค/[๋ถ€์ŠคํŠธ์„œํฌํ„ฐ์ฆˆ3๊ธฐ]์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘

[๋ถ€์ŠคํŠธ์ฝ”์Šค]์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘(ํ”„๋กœ๊ทธ๋ž˜๋ฐ, ์กฐ๊ฑด๋ฌธ, ๋น„๊ต์—ฐ์‚ฐ์ž์™€ ๋ธ”๋ฆฌ์–ธ, ์กฐ๊ฑด๋ฌธ, ๋ฆฌํŒฉํ† ๋ง)

mmin.h 2021. 1. 15. 10:11

์•ˆ๋…•ํ•˜์„ธ์š” ๋ถ€์Šคํ„ฐ์ฝ”์Šค 3๊ธฐ ์„œํฌํ„ฐ์ฆˆ ํ—ˆ๋ธŒ์ž…๋‹ˆ๋‹ค. ๐ŸŒฟ

๋ถ€์Šคํ„ฐ์ฝ”์Šค๋ž€?

์ปค๋„ฅํŠธ์žฌ๋‹จ์€ ๋„ค์ด๋ฒ„๊ฐ€ ์„ค๋ฆฝํ•œ ๋น„์˜๋ฆฌ ๊ต์œก ์žฌ๋‹จ์ž…๋‹ˆ๋‹ค.
์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์ž ์–‘์„ฑ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ, ๋ถ€์ŠคํŠธ์ฝ”์Šค์™€ ํ•จ๊ป˜
๋‹น์‹ ์˜ ๊ฐœ๋ฐœ ์ปค๋ฆฌ์–ด๋ฅผ ์—…๊ทธ๋ ˆ์ด๋“œํ•˜์„ธ์š”!

 

์ œ ํฌ์ŠคํŒ…์€ ๊ฐ•์˜ ๋‚ด ์ƒ๊ฐํ•ด๋ณด๊ธฐ์™€ ์ˆ˜์—…์—์„œ ๋‹ค๋ฃจ๋Š” ์ฝ”๋“œ๋ฅผ ์ง์ ‘ ํฌ๋กฌํ™”๋ฉด์—์„œ ํ™•์ธ ํ•ด๋ณผ ์ˆ˜ ์žˆ๋„๋ก ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๊ด€๋ จ๋œ ๊ฐœ๋…๊ณผ ๊ฐ•์˜๋Š” ํ•จ๊ป˜ ์˜ฌ๋ ค๋“œ๋ฆฌ๋Š” ๋งํฌ์—์„œ ํ™•์ธํ•ด๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

www.boostcourse.org/cs124/joinLectures/52258

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘

๋ถ€์ŠคํŠธ์ฝ”์Šค ๋ฌด๋ฃŒ ๊ฐ•์˜

www.boostcourse.org


ํ”„๋กœ๊ทธ๋žจ, ํ”„๋กœ๊ทธ๋ž˜๋จธ, ํ”„๋กœ๊ทธ๋ž˜๋ฐ

www.boostcourse.org/cs124/lecture/194603

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘

๋ถ€์ŠคํŠธ์ฝ”์Šค ๋ฌด๋ฃŒ ๊ฐ•์˜

www.boostcourse.org

ํ”„๋กœ๊ทธ๋žจ์—๋Š” ์ˆœ์„œ๋ผ๋Š” ์˜๋ฏธ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋ฐ์€ ์ด๋Ÿฌํ•œ ์ˆœ์„œ๋ฅผ ๋งŒ๋“œ๋Š” ํ–‰์œ„๋ฅผ ๋งํ•˜์ฃ . ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” ์ด๋Ÿฌํ•œ ์ˆœ์„œ๋ฅผ ๋งŒ๋“œ๋Š” ์ผ์„ ํ•˜๋Š” ์‚ฌ๋žŒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์šฉ์–ด๋Š” ์†Œํ”„ํŠธ์›จ์–ด ๋ถ„์•ผ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค์–‘ํ•œ ๋ถ„์•ผ์—์„œ๋„ ์‚ฌ์šฉ๋˜๋Š” ๋ง์ž…๋‹ˆ๋‹ค.

์ปดํ“จํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ์—๋Š” ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ˆœ์„œ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋ณดํ†ต์€ ์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ์ด ๋ฐ˜๋ณต์ ์œผ๋กœ ์ด์šฉ๋ฉ๋‹ˆ๋‹ค. ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ž€ ์‹œ๊ฐ„์˜ ์ˆœ์„œ์— ๋”ฐ๋ผ์„œ ์‹คํ–‰๋˜์–ด์•ผ ํ•  ๊ธฐ๋Šฅ์„ ๊ธ€๋กœ ์ ์–ด๋‘๋Š” ๋ฐฉ์‹์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ž‘์—…์ด ํ•„์š”ํ•  ๋•Œ๋งˆ๋‹ค ์ ์–ด๋‘” ๊ธ€์„ ์ปดํ“จํ„ฐ๊ฐ€ ์‹คํ–‰ํ•˜๋„๋ก ๊ฑด๋„ค์ฃผ๋Š” ๊ฒƒ์ด์ฃ .

 

HTML๊ณผ Javascript์˜ ๋น„๊ต

 

HTML๋กœ ๋งŒ๋“  ์›นํŽ˜์ด์ง€๋Š” ์‹œ๊ฐ„์˜ ์ˆœ์„œ์— ๋”ฐ๋ผ ์‹คํ–‰๋˜์ง€ ์•Š๊ณ , ํ•œ ๋ฒˆ ๋งŒ๋“ค์–ด์ง€๋ฉด ๋ฐ”๋€Œ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋•Œ๋ฌธ์— HTML์€ ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๊ฐ€ ์•„๋‹Œ ๊ฒƒ์ด์ฃ .

๋ฐ˜๋ฉด์— Javascript๋Š” ์‚ฌ์šฉ์ž์™€ ์ƒํ˜ธ์ž‘์šฉํ•˜๊ณ , ์ด๋ฅผ ์œ„ํ•ด์„œ ์‹œ๊ฐ„์— ๋”ฐ๋ผ ์—ฌ๋Ÿฌ ๊ธฐ๋Šฅ์ด ์‹คํ–‰๋˜์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด๋ผ๋Š” ํ˜•ํƒœ๋ฅผ ๋„๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ Javascript๋Š” ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ผ๊ณ  ๋ถ€๋ฅผ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๋” ๋‚˜์•„๊ฐ€์„œ ์‹œ๊ฐ„์— ๋”ฐ๋ผ ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜๋Š” ๊ฒƒ ์™ธ์—๋„, ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜๋„๋ก ํ•˜๊ฑฐ๋‚˜, ๊ฐ™์€ ์ฝ”๋“œ๊ฐ€ ๋ฐ˜๋ณต์ ์œผ๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•๋„ ๊ณ ์•ˆํ•˜๊ฒŒ ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

์ƒ๊ฐํ•ด๋ณด๊ธฐ

์ด๋ฒˆ ๊ฐ•์˜์—์„œ HTML๊ณผ๋Š” ๋‹ฌ๋ฆฌ Javascript๋Š” ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ผ๋Š” ๊ฒƒ์„ ๋ฐฐ์› ์Šต๋‹ˆ๋‹ค. ์˜ค๋Š˜ ๋ฐฐ์šด ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ HTML์€ ์™œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๊ฐ€ ์•„๋‹Œ์ง€ ์Šค์Šค๋กœ์—๊ฒŒ ์„ค๋ช…ํ•ด๋ด…์‹œ๋‹ค.

 

"HTML์ด ์™œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด ์•„๋‹ˆ๋‚˜๋ฉด ํ”„๋กœ๊ทธ๋žจ์ด ๋˜๊ธฐ ์œ„ํ•ด์„  ์‹œ๊ฐ„์— ๋”ฐ๋ฅธ ๋กœ์ง์ด ๋ฐœ์ƒํ•˜์—ฌ์•ผ ํ•˜๋Š”๋ฐ HTML ์€ ๋‹จ์ˆœํžˆ ๋ฌ˜์‚ฌํ•˜๊ณ  ์ •์ ์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค."


์กฐ๊ฑด๋ฌธ

https://www.boostcourse.org/cs124/lecture/194604/

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘

๋ถ€์ŠคํŠธ์ฝ”์Šค ๋ฌด๋ฃŒ ๊ฐ•์˜

www.boostcourse.org

์กฐ๊ฑด๋ฌธ์ด๋ž€ ํ”„๋กœ๊ทธ๋žจ์ด ์กฐ๊ฑด์— ๋”ฐ๋ผ์„œ ๋‹ค๋ฅธ ๊ธฐ๋Šฅ๋“ค์ด ๋‹ค๋ฅธ ์ˆœ์„œ์— ๋”ฐ๋ผ์„œ ์‹คํ–‰๋˜๋„๋ก ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์กฐ๊ฑด๋ฌธ์€ ๋‹จ์ˆœํ•˜๊ณ  ๋ฐ˜๋ณต์ ์ธ ์—…๋ฌด ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ณต์žกํ•œ ์—…๋ฌด๊นŒ์ง€๋„ ์ปดํ“จํ„ฐ๊ฐ€ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๋„๋ก ํ•ด ์ค๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ์šฐ๋ฆฌ๊ฐ€ ์ง€๊ธˆ๊นŒ์ง€ ๋งŒ๋“ค์—ˆ๋˜ night/day ๋ฒ„ํŠผ ์˜ˆ์ œ์— ๋Œ€ํ•ด์„œ ์ƒ๊ฐํ•ด๋ด…์‹œ๋‹ค. ์ง€๊ธˆ๊นŒ์ง€๋Š” night์™€ day์˜ ๋ฒ„ํŠผ์„ ๋”ฐ๋กœ ๋งŒ๋“ค์–ด์„œ ๊ฐ๊ฐ์˜ ๋™์ž‘์„ ์ง€์ •ํ•ด ์ฃผ์—ˆ์ฃ .

ํ•˜์ง€๋งŒ, ํ˜„์žฌ ์ƒํƒœ๊ฐ€ night๋ผ๋ฉด day ๋ชจ๋“œ๋กœ, ํ˜„์žฌ ์ƒํƒœ๊ฐ€ day๋ผ๋ฉด night๋ชจ๋“œ๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๋„๋ก ๋งŒ๋“ค๋ฉด, ๋ฒ„ํŠผ์„ ๋‘ ๊ฐœ ๋งŒ๋“ค ํ•„์š” ์—†์ด ํ•˜๋‚˜๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋  ๊ฒ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ฒ„ํŠผ์„ ํ† ๊ธ€์ด๋ผ๊ณ  ๋ถ€๋ฆ…๋‹ˆ๋‹ค.

 

์ง€๊ธˆ๋ถ€ํ„ฐ if/else ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ ์ด๋Ÿฌํ•œ ํ† ๊ธ€์„ ๊ตฌํ˜„ํ•ด๋ด…์‹œ๋‹ค.

if ์กฐ๊ฑด๋ฌธ์„ ์จ์„œ ํ˜„์žฌ์˜ mode๊ฐ€ 'day'๋กœ ์ง€์ •๋˜์–ด ์žˆ์„ ๋•Œ ์‹คํ–‰๋  ์ฝ”๋“œ๋ฅผ ์ง€์ •ํ•˜๊ณ , ๊ทธ๋ ‡์ง€ ์•Š์„ ๊ฒฝ์šฐ์—๋Š” else ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ mode๊ฐ€ 'night'๋กœ ์ง€์ •๋˜์–ด ์žˆ์„ ๋•Œ ์‹คํ–‰๋  ์ฝ”๋“œ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ƒ๊ฐํ•ด๋ณด๊ธฐ

1) ์กฐ๊ฑด๋ฌธ์ด ํ•„์š”ํ•œ ์ด์œ ๊ฐ€ ๋ฌด์—‡์ผ๊นŒ์š”? ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•˜๋ฉด ์–ด๋–ค ์ ์ด ๋” ํŽธ๋ฆฌํ• ๊นŒ์š”? ์˜ˆ์‹œ๋ฅผ ๋“ค์–ด์„œ ์ƒ๊ฐํ•ด๋ด…์‹œ๋‹ค.

 

"๋งŒ์•ฝ ๋‹ค์Œ ์ˆ˜์—…์˜ boolean ์˜ ๋Œ€ํ•ด์„œ ์•ˆ๋‹ค๋ฉด toggle ์˜ ๋‚ด์šฉ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ณ , ์ฝ”๋”ฉ์„ ์ฒ˜์Œ ์ง„ํ–‰ํ•ด๋ณธ๋‹ค๋ฉด ์ˆ˜์—…์„ ๋“ฃ๋Š”๋‹ค. ์ด์ฒ˜๋Ÿผ ์กฐ๊ฑด๋ฌธ์€ ์šฐ๋ฆฌ์˜ ์‹œ๊ฐ„๊ณผ ๋น„์šฉ์„ ์ ˆ์•ฝํ•ด์ค€๋‹ค."


๋น„๊ต์—ฐ์‚ฐ์ž์™€ ๋ธ”๋ฆฌ์–ธ

https://www.boostcourse.org/cs124/lecture/194605/

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘

๋ถ€์ŠคํŠธ์ฝ”์Šค ๋ฌด๋ฃŒ ๊ฐ•์˜

www.boostcourse.org

๋น„๊ต ์—ฐ์‚ฐ์ž ===

Javascript์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์“ฐ์ด๋Š” ๋น„๊ต ์—ฐ์‚ฐ์ž๋Š” ๋™๋“ฑ ๋น„๊ต ์—ฐ์‚ฐ์ž **===**์ž…๋‹ˆ๋‹ค. ์ด ๋น„๊ต ์—ฐ์‚ฐ์ž๋Š” ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ์ด ๊ฐ™์€์ง€ ํŒ๋‹จํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๊ฒฐ๊ณผ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”?

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Compraison operators & bollean</title>
</head>

<body>
    <h1>Compraison operators & bollean</h1>
    <h2>===</h2>
    <h3>1===1</h3>
    <script>
        document.write(1 === 1); //true
    </script>
    <h3>1===2</h3>
    <script>
        document.write(1 === 2); //false
    </script>

</body>

</html>

๋น„๊ต ์—ฐ์‚ฐ์ž ===

 

Javascript์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์“ฐ์ด๋Š” ๋น„๊ต ์—ฐ์‚ฐ์ž๋Š” ๋™๋“ฑ ๋น„๊ต ์—ฐ์‚ฐ์ž **===**์ž…๋‹ˆ๋‹ค. ์ด ๋น„๊ต ์—ฐ์‚ฐ์ž๋Š” ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ์ด ๊ฐ™์€์ง€ ํŒ๋‹จํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๊ฒฐ๊ณผ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”?

์—ฌ๊ธฐ์„œ ์•Œ ์ˆ˜ ์žˆ๋Š” ์ ์€, ๋น„๊ต ์—ฐ์‚ฐ์ž ===๋Š” ์ดํ•ญ ์—ฐ์‚ฐ์ž๋ผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฆ‰ ์ขŒํ•ญ๊ณผ ์šฐํ•ญ์„ ๊ฒฐํ•ฉํ•ด์„œ ๊ทธ ๊ด€๊ณ„์— ๋”ฐ๋ผ ํ•˜๋‚˜์˜ ๊ฒฐ๊ณผ, ์ฆ‰ True์ธ์ง€ False์ธ์ง€๋ฅผ ๋งŒ๋“ค์–ด๋‚ด๋Š” ๊ฒƒ์ด์ฃ .

 

๋ถˆ๋ฆฌ์–ธ(Boolean)

์ด๋ ‡๊ฒŒ ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฒฐ๊ณผ๋กœ True ํ˜น์€ False๊ฐ€ ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค. ์ด ๋•Œ ์ด True์™€ Fasle๋ฅผ ๋ณด๊ณ  ๋ถˆ๋ฆฌ์–ธ(Boolean) ๋ฐ์ดํ„ฐ ํƒ€์ž…์ด๋ผ๊ณ  ๋ถ€๋ฆ…๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ์ด์ „์— ๋ฐฐ์› ๋˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ธ ์ˆซ์ž(Number)๋‚˜ ๋ฌธ์ž์—ด(String)์—๋Š” ์•„์ฃผ ๋งŽ์€ ์ข…๋ฅ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋ถˆ๋ฆฌ์–ธ์—๋Š” True ์•„๋‹ˆ๋ฉด False, ๋”ฑ ๋‘๊ฐ€์ง€๋งŒ์ด ์กด์žฌํ•˜์ฃ .

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Compraison operators & bollean</title>
</head>

<body>
    <h1>Compraison operators & bollean</h1>
    <h2>===</h2>
    <h3>1&lt;1</h3>
    <script>
        document.write(1 < 1); //false
    </script>
    <h3>1&lt;2</h3>
    <script>
        document.write(1 < 2); //true
    </script>

</body>

</html>

๋น„๊ต ์—ฐ์‚ฐ์ž <, >

๋˜ ๋‹ค๋ฅธ ๋น„๊ต ์—ฐ์‚ฐ์ž๋กœ๋Š” ๋‘ ๊ฐ’์˜ ํฌ๊ธฐ๋ฅผ ์„œ๋กœ ๋น„๊ตํ•˜๋Š” ์—ฐ์‚ฐ์ž๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ํ”ํžˆ ๋ถ€๋“ฑํ˜ธ๋ผ๊ณ  ๋ถ€๋ฅด๋Š” **<, >**์™€ ๊ฐ™์€ ๊ฒƒ๋“ค์ด์ฃ . ์ด๋ฅผ HTML์—์„œ ์“ธ ๋•Œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์”๋‹ˆ๋‹ค.

HTML์—์„œ๋Š” ์ด ๊บฝ์‡  ๊ธฐํ˜ธ(<,>)๊ฐ€ ํƒœ๊ทธ๋ฅผ ๋‚˜ํƒ€๋‚ผ ๋•Œ ์“ฐ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ˜ผ๋ž€์„ ์ค„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด์ฃ . <๊ฐ€ <๋ฅผ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์ด๊ณ , >๊ฐ€ >๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

Javascript์—์„œ๋Š” ๊ทธ๋Œ€๋กœ <, >๋กœ ๋‚˜ํƒ€๋‚ด๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ Javascript ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๊ฒฐ๊ณผ๋Š” ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”?

 

1) Javascript์—์„œ '์™ผ์ชฝ์ด ์˜ค๋ฅธ์ชฝ๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๋‹ค'๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์–ด๋–ป๊ฒŒ ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹์„๊นŒ์š”? (ํžŒํŠธ: javascript bigger than or equal to ๋ผ๊ณ  ๊ฒ€์ƒ‰ํ•ด๋ณด์„ธ์š”!)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than_or_equal

 

Greater than or equal (>=) - JavaScript | MDN

The greater than or equal operator (>=) returns true if the left operand is greater than or equal to the right operand, and false otherwise. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the intera

developer.mozilla.org

console.log(5 >= 3);
// expected output: true

console.log(3 >= 3);
// expected output: true

console.log(3n >= 5);
// expected output: false

console.log('ab' >= 'aa');
// expected output: true

 

์ƒ๊ฐํ•ด๋ณด๊ธฐ

 

๋‹ค์Œ ์ฝ”๋“œ์˜ ์‹คํ–‰ ๊ฒฐ๊ณผ๋Š” ๋ฌด์—‡์ผ๊นŒ์š”?

1+1 > 1+2 //false


์กฐ๊ฑด๋ฌธ

https://www.boostcourse.org/cs124/lecture/194606/

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘

๋ถ€์ŠคํŠธ์ฝ”์Šค ๋ฌด๋ฃŒ ๊ฐ•์˜

www.boostcourse.org

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>Conditional statements</h1>
    <h2>Program</h2>
    <script>
        document.write("1<br>");
        document.write("2<br>");
        document.write("3<br>");
        document.write("4<br>");
    </script>
    <h2>IF-true</h2>
    <script>
        document.write("1<br>");
        if (true) {
            document.write("2<br>");
        } else {
            document.write("3<br>");
        }
        document.write("4<br>");
    </script>
     <h2>IF-false</h2>
     <script>
         document.write("1<br>");
         if (false) {
             document.write("2<br>");
         } else {
             document.write("3<br>");
         }
         document.write("4<br>");
     </script>
</body>

</html>

 

์ด ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด ์•„๊นŒ์™€๋Š” ๋‹ฌ๋ฆฌ 13์ด ์ถœ๋ ฅ๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด **if(true)**์™€ if(false), ๊ทธ๋ฆฌ๊ณ  else๊ฐ€ ์–ด๋–ค ์—ญํ• ์„ ํ•˜๊ธธ๋ž˜ ์ด๋Ÿฐ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒƒ์ผ๊นŒ์š”?

if๋ฌธ์˜ ๊ด„ํ˜ธ ์•ˆ์—๋Š” ๋ถˆ๋ฆฌ์–ธ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ด ์˜ต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋งŒ์•ฝ ๊ทธ ๋ถˆ๋ฆฌ์–ธ์ด true์ด๋ฉด ์ฒซ ๋ฒˆ์งธ ์ค‘๊ด„ํ˜ธ์— ์žˆ๋Š” ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜๊ณ , else์˜ ์ค‘๊ด„ํ˜ธ์— ์žˆ๋Š” ์ฝ”๋“œ๋Š” ๋ฌด์‹œ๋ฉ๋‹ˆ๋‹ค. ๋ฐ˜๋Œ€๋กœ ๊ทธ ๋ถˆ๋ฆฌ์–ธ์ด false์ด๋ฉด else์˜ ์ค‘๊ด„ํ˜ธ์— ์žˆ๋Š” ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜๊ณ  ์ฒซ ๋ฒˆ์งธ ์ค‘๊ด„ํ˜ธ์— ์žˆ๋Š” ์ฝ”๋“œ๊ฐ€ ๋ฌด์‹œ๋˜๊ฒ ์ฃ .

 

์ง€๊ธˆ ์ง  ์ฝ”๋“œ์—์„œ๋Š” ๊ด„ํ˜ธ ์•ˆ์— ์žˆ๋Š” ๋ถˆ๋ฆฌ์–ธ์ด ๊ณ ์ •๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•ญ์ƒ ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, ์ด ๊ด„ํ˜ธ ์•ˆ์— ์žˆ๋Š” ๋ถˆ๋ฆฌ์–ธ์ด ์ƒํ™ฉ์— ๋”ฐ๋ผ์„œ true/false๊ฐ€ ๋ฐ”๋€Œ๋„๋ก ๋งŒ๋“ค์–ด์ฃผ๋ฉด, ์ƒํ™ฉ์— ๋”ฐ๋ผ์„œ ๋‹ค๋ฅธ ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜๋„๋ก ๋งŒ๋“ค์–ด์ค„ ์ˆ˜ ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค.

 

 

์ƒ๊ฐํ•ด๋ณด๊ธฐ

 

1) ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜์˜€์„ ๋•Œ์˜ ๊ฒฐ๊ณผ๋Š” ๋ฌด์—‡์ผ๊นŒ์š”?

<script>
  document.write('1')
  if(true) {
    document.write('2')
  }
  else {
    document.write('3')
  }
  if(false) {
    document.write('4')
  }
  else {
    document.write('5')
  }
  document.write('6')
</script>

์ด์œ ๋Š” ๋จผ์ € 1์ด ์‹คํ–‰๋˜๊ณ , 2๋Š” true ์ด๊ธฐ ๋•Œ๋ฌธ์— ์กฐ๊ฑด์„ ๋งŒ์กฑํ•œ๋‹ค ํ•˜์ง€๋งŒ 3์€ else ์— ์˜ํ•ด ์‹คํ–‰๋˜์ง€ ์•Š๊ณ , 4๋Š” 1f์˜ ์กฐ๊ฑด๋ฌธ์ด false ์ด๊ธฐ ๋•Œ๋ฌธ์— ์‹คํ–‰์ด ๋˜์ง€ ์•Š๊ณ  6์€ false์˜ else ๋ฌธ์— ์˜ํ•ด ์‹คํ–‰๋œ๋‹ค.


์กฐ๊ฑด๋ฌธ์˜ ํ™œ์šฉ

https://www.boostcourse.org/cs124/lecture/194607/

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘

๋ถ€์ŠคํŠธ์ฝ”์Šค ๋ฌด๋ฃŒ ๊ฐ•์˜

www.boostcourse.org

javascript get value

https://stackoverflow.com/questions/11563638/how-do-i-get-the-value-of-text-input-field-using-javascript

 

How do I get the value of text input field using JavaScript?

I am working on a search with JavaScript. I would use a form, but it messes up something else on my page. I have this input text field:

stackoverflow.com

document.getElementById('textbox_id').value to get the value of desired box

For example, document.getElementById("searchTxt").value;

 

์กฐ๊ฑด๋ฌธ์„ ํ™œ์šฉํ•œ ํ† ๊ธ€ ๋งŒ๋“ค๊ธฐ

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ์กฐ๊ฑด๋ฌธ์„ ํ™œ์šฉํ•ด์„œ ํ† ๊ธ€์„ ๋งŒ๋“ค์–ด ๋ณผ๊ฒ๋‹ˆ๋‹ค. ๋จผ์ € ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฒ„ํŠผ์„ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค.

์ง€๊ธˆ๋ถ€ํ„ฐ ์ด ๋ฒ„ํŠผ์˜ value ๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ, ์ด value๊ฐ€ night๋ฉด day ๋ฒ„์ „์œผ๋กœ ๋ฐ”๋€Œ๋Š” ์ฝ”๋“œ๋ฅผ, day๋ฉด night ๋ฒ„์ „์œผ๋กœ ๋ฐ”๋€Œ๋Š” ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค๊ฒ๋‹ˆ๋‹ค.

 

์ด๊ฒƒ์ด ์–ด๋ ค์šฐ์‹œ๋‹ค๋ฉด ์œ„์˜ ๋งํฌ๋ฅผ ๋‹ฌ์•„๋‘์—ˆ์Šต๋‹ˆ๋‹ค. ํ™•์ธ ๋ฐ”๋ž๋‹ˆ๋‹ค.

 

๋ฒ„ํŠผ์˜ onclick ์†์„ฑ ์•ˆ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ Javascript ์ฝ”๋“œ๋ฅผ ์จ ๋ด…์‹œ๋‹ค.

ํ˜„์žฌ ํŽ˜์ด์ง€์—์„œ querySelector์„ ์‚ฌ์šฉํ•ด์„œ id๊ฐ€ night_day์ธ ํƒœ๊ทธ๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด์„œ id๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” #์„ ๋ถ™์—ฌ์ค๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ฐพ์•„๋‚ธ ํƒœ๊ทธ์˜ value๋ฅผ ์•Œ๊ธฐ ์œ„ํ•ด์„œ .value๋ฅผ ์จ ์ค๋‹ˆ๋‹ค.

 

์ด๋ ‡๊ฒŒ ๊ฐ€์ ธ์˜จ value ๊ฐ’์„ night์™€ ๋น„๊ตํ•˜๋ฉด ๋˜๊ฒ ์ฃ . ๊ทธ๋ ‡๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์จ ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์ด ์ฝ”๋“œ์—๋Š” ๊ฒฐ์ •์ ์ธ ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ”๋กœ ๋ฒ„ํŠผ์ด ๋ˆŒ๋ฆด ๋•Œ๋งˆ๋‹ค value๊ฐ€ ๋ฐ”๋€Œ์ง€ ์•Š๋Š” ๊ฒƒ์ด์ฃ . ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ํ•ญ์ƒ ์›๋ž˜ ์„ค์ •๋œ value์ธ night์— ํ•ด๋‹นํ•˜๋Š” ์ฝ”๋“œ, ์ฆ‰ ์ฒซ ๋ฒˆ์งธ ์ค‘๊ด„ํ˜ธ์— ์žˆ๋Š” ์ฝ”๋“œ๋งŒ ์‹คํ–‰๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋  ๋•Œ๋งˆ๋‹ค value๋ฅผ ๋ฐ”๊ฟ”์ฃผ๋Š” ์ฝ”๋“œ๋„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WEB1 - javaScript</title>
</head>

<body style="">
    <h1><a href="index.html">WEB</a></h1>
    <input type="button" value="night" onclick="
        document.querySelector('body').style.backgroundColor = 'black';
        document.querySelector('body').style.color = 'white';
    ">
    <input type="button" value="day" onclick="
        document.querySelector('body').style.backgroundColor = 'white';
        document.querySelector('body').style.color = 'black';
    ">
    <input id="night_day" type="button" value="night" onclick="
    if(document.querySelector('#night_day').value === 'night'){
        document.querySelector('body').style.backgroundColor = 'black';
        document.querySelector('body').style.color = 'white';
        document.querySelector('#night_day').value = 'day'
    }
    else{
        document.querySelector('body').style.backgroundColor = 'white';
        document.querySelector('body').style.color = 'black';
        document.querySelector('#night_day').value = 'night'
    }

    ">
    <ol>
        <li><a href="1.html">HTML</a></li>
        <li><a href="2.html">CSS</a></li>
        <li><a href="3.html">JAVASCRIPT</a></li>
    </ol>
    <h2>JavaScript</h2>
    <p>
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente officia incidunt quas reprehenderit alias
        eveniet necessitatibus eligendi harum obcaecati temporibus, odit, dolor nulla adipisci tempore illum suscipit
        quod voluptatibus debitis quam atque nemo accusantium voluptatum voluptates voluptas. Laudantium labore,
        praesentium architecto perspiciatis enim totam! Magni fugit corporis iste ratione dolorem temporibus. Magni
        perferendis aspernatur mollitia! Eaque dolorem, exercitationem corrupti amet aliquid quis ab eligendi. Nam odio
        maxime quae explicabo repellat velit error fuga dolores quo quia. Quidem beatae iusto dolore eos, consequatur
        fuga magnam! Sed esse asperiores dolor et adipisci corrupti eveniet tempore deleniti rerum possimus natus,
        reiciendis accusantium ut reprehenderit! Animi quaerat ratione, facere saepe iusto eos, obcaecati, provident
        ius doloribus nam! Modi, hic! Est vel ipsam laborum placeat! Non nulla dolorum autem corrupti.
    </p>
</body>

</html>

๋ฆฌํŒฉํ† ๋ง(์ค‘๋ณต์˜ ์ œ๊ฑฐ)

https://www.boostcourse.org/cs124/lecture/194611/

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘

๋ถ€์ŠคํŠธ์ฝ”์Šค ๋ฌด๋ฃŒ ๊ฐ•์˜

www.boostcourse.org

๋ฆฌํŒฉํ† ๋ง - this ์‚ฌ์šฉํ•˜๊ธฐ

๋ฆฌํŒฉํ† ๋ง์ด๋ž€ ๋น„ํšจ์œจ์ ์ธ ์ฝ”๋“œ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ๊ฐ€๋…์„ฑ์„ ๋†’์ด๊ณ  ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์‰ฝ๋„๋ก ๋งŒ๋“œ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฝ”๋“œ์˜ ๊ธฐ๋Šฅ์ ์ธ ๋ฉด์—์„œ๋Š” ๋ณ€ํ™”๊ฐ€ ์—†๋„๋ก ๋ง์ด์ฃ . ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ์ฝ”๋“œ์˜ ๋น„ํšจ์œจ์ ์ธ ๋ถ€๋ถ„์„ ์ฐพ์•„๋‚ด์„œ ๊ณ ์ณ๋ณด๋Š” ๋ฆฌํŒฉํ† ๋ง ์ž‘์—…์„ ์ง„ํ–‰ํ•ด๋ด…์‹œ๋‹ค.

์ง€๋‚œ ๊ฐ•์˜์—์„œ ์™„์„ฑํ•œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ† ํด ์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ด…์‹œ๋‹ค.

 

<input type="button" value="night" onclick="
    if(this.value === 'night'){
        document.querySelector('body').style.backgroundColor = 'black';
        document.querySelector('body').style.color = 'white';
        this.value = 'day'
    }
    else{
        document.querySelector('body').style.backgroundColor = 'white';
        document.querySelector('body').style.color = 'black';
        this.value = 'night'
    }
    ">

์—ฌ๊ธฐ์—์„œ๋Š” ์ž๊ธฐ๊ฐ€ ์†ํ•œ ๋ฒ„ํŠผ์„ ์ฐพ๊ธฐ ์œ„ํ•ด์„œ document.querySelector('#night_day') ๋ผ๋Š” ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋งŒ์•ฝ ์ด ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌํ•ด์„œ ํ•˜๋‚˜์˜ ๋ฒ„ํŠผ์„ ๋” ๋งŒ๋“ค๊ฒŒ ๋œ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”?

 

id๋Š” ํ•˜๋‚˜์˜ ํƒœ๊ทธ์—๋งŒ ์ ์šฉ๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ƒˆ๋กญ๊ฒŒ ๋งŒ๋“ค์–ด์ง„ ๋ฒ„ํŠผ์—๋Š” ์ƒˆ๋กœ์šด id๊ฐ’์„ ์ ์šฉํ•ด์ค˜์•ผ๊ฒ ์ฃ . ์˜ˆ๋ฅผ ๋“ค์–ด์„œ ์ƒˆ๋กญ๊ฒŒ ๋งŒ๋“  ๋ฒ„ํŠผ์˜ id๋ฅผ #night_day2๋ผ๊ณ  ๋งŒ๋“ค์—ˆ๋‹ค๊ณ  ํ•ด ๋ด…์‹œ๋‹ค. ๊ทธ๋ ‡๊ฒŒ ๋˜๋ฉด ์ด ์ฝ”๋“œ์—์„œ ๋ชจ๋“  #night_day๋ฅผ #night_day2๋กœ ์ง์ ‘ ๋ฐ”๊ฟ”์ฃผ๋Š” ์ž‘์—…์„ ์ง„ํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ฌด์ฒ™ ๋น„ํšจ์œจ์ ์ด์ฃ .

 

๊ทธ๋ž˜์„œ Javascript์—๋Š” ์ž๊ธฐ ์ž์‹ ์„ ๊ฐ€๋ฆฌํ‚ค๊ธฐ ์œ„ํ•œ this๋ผ๋Š” ํ‚ค์›Œ๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. document.querySelector('#night_day') ๋Œ€์‹  this๋ฅผ ์จ๋„ ๋˜๋Š” ๊ฒƒ์ด์ฃ . ๊ทธ๋Ÿฌ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์“ธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

<input type="button" value="night" onclick="
        var target = document.querySelector('body'); 
    if(this.value === 'night'){
        
        target.style.backgroundColor = 'black';
        target.style.color = 'white';
        this.value = 'day'
    }
    else{
        target.style.backgroundColor = 'white';
        target.style.color = 'black';
        this.value = 'night'
    }
    ">

์ฝ”๋“œ๊ฐ€ ํ›จ์”ฌ ๊ฐ„๊ฒฐํ•ด์ง„ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ์ด ์ฝ”๋“œ๋Š” ๋ช‡ ๋ฒˆ์„ ๋ณต์‚ฌํ•ด์„œ ๋ถ™์—ฌ๋„ฃ๋”๋ผ๋„ ๋”ฐ๋กœ ์ถ”๊ฐ€์ ์ธ ์ˆ˜์ • ์—†์ด ๊ณ„์† ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋ฆฌํŒฉํ† ๋ง - ์ค‘๋ณต ์ œ๊ฑฐํ•˜๊ธฐ

๋‘ ๋ฒˆ์งธ๋กœ ๋ฆฌํŒฉํ† ๋ง ํ•ด ๋ณผ ๋ถ€๋ถ„์€ ๋ฐ”๋กœ document.querySelector('body') ์ž…๋‹ˆ๋‹ค. ์ด ๋ถ€๋ถ„์ด ๋ฌด๋ ค 4๋ฒˆ์ด๋‚˜ ๋“ฑ์žฅํ•˜๊ณ  ์žˆ์ฃ . ์ฝ”๋”ฉ์„ ํ•  ๋•Œ์—๋Š” ์ค‘๋ณต์„ ์—†์• ์ฃผ๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์ด ๋ถ€๋ถ„์„ ์ œ๊ฑฐํ•ด๋ณด๋„๋ก ํ•ฉ์‹œ๋‹ค.

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด target์ด๋ผ๋Š” ๋ณ€์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์„œ ๊ฑฐ๊ธฐ์— body ํƒœ๊ทธ๋ฅผ ์ฐพ์•„์„œ ๋„ฃ๊ณ , ์ด target ๋ณ€์ˆ˜๋งŒ ๊ฐ„๋‹จํ•˜๊ฒŒ ์‚ฌ์šฉํ•ด์„œ ์ฝ”๋“œ์˜ ๊ธธ์ด๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ฒซ ๋ฒˆ์งธ ์ค„๋งŒ ์ˆ˜์ •ํ•ด์ฃผ๋ฉด, target์ด ์“ฐ์ด๋Š” ๋„ค ์ค„์„ ๋ชจ๋‘ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ๋„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ƒ๊ฐํ•ด๋ณด๊ธฐ

 

1) ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ์—์„œ ๋ฆฌํŒฉํ† ๋ง์„ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์„ ์ฐพ์•„์„œ ๊ณ ์ณ๋ด…์‹œ๋‹ค.

if(document.querySelector('h1').value === 'night') {
  document.querySelector('body').style.backgroundColor = 'black';
  document.querySelector('h1').style.color = 'white';
  document.querySelector('h1').value = 'day';
}
else {
  document.querySelector('body').style.backgroundColor = 'white';
  document.querySelector('h1').style.color = 'black';
  document.querySelector('h1').value = 'night';
}
var target_h1 = document.querySElector('h1');
var target_body = document.querySElector('body');


if(document.querySelector('h1').value === 'night') {
    target_body.style.backgroundColor = 'black';
    target_h1.style.color = 'white';
    target_h1.value = 'day';
  }
  else {
    target_body.style.backgroundColor = 'white';
    target_h1.style.color = 'black';
    target_h1.value = 'night';
  }

www.boostcourse.org/

 

๋‹ค ํ•จ๊ป˜ ๋ฐฐ์šฐ๊ณ  ์„ฑ์žฅํ•˜๋Š” ๋ถ€์ŠคํŠธ์ฝ”์Šค

๋ถ€์ŠคํŠธ์ฝ”์Šค(boostcourse)๋Š” ๋ชจ๋‘ ํ•จ๊ป˜ ๋ฐฐ์šฐ๊ณ  ์„ฑ์žฅํ•˜๋Š” ๋น„์˜๋ฆฌ SW ์˜จ๋ผ์ธ ํ”Œ๋žซํผ์ž…๋‹ˆ๋‹ค.

www.boostcourse.org

github.com/hhhminme

 

hhhminme - Overview

๊พธ์ค€ํžˆ ๊ณต๋ถ€์ค‘์ธ ์ดˆ๋ณด ๊ฐœ๋ฐœ์ž์ง€๋ง์ƒ hub@kakao.com. hhhminme has 12 repositories available. Follow their code on GitHub.

github.com