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

[๋ถ€์ŠคํŠธ์ฝ”์Šค]์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘(๋ฐฐ์—ด๊ณผ ๋ฐ˜๋ณต๋ฌธ, ํ™œ์šฉ)

mmin.h 2021. 1. 26. 15:56

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

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

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

 

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

www.boostcourse.org/cs124/joinLectures/52258

 

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

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

www.boostcourse.org


๋ฐฐ์—ด๊ณผ ๋ฐ˜๋ณต๋ฌธ

www.boostcourse.org/cs124/lecture/194615

 

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

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

www.boostcourse.org

์šฐ๋ฆฌ๋Š” ์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์—ด๊ณผ while ๋ฐ˜๋ณต๋ฌธ์— ๋Œ€ํ•ด์„œ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ด๋ฒˆ์—๋Š” ์ด ๋‘ ๊ฐ€์ง€๋ฅผ ๊ฒฐํ•ฉ์‹œ์ผœ ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฐ์—ด์ด ์žˆ๋‹ค๊ณ  ํ•ด ๋ด…์‹œ๋‹ค.

fruits = ["apple", "banana", "coconut"];

์ง€๊ธˆ๋ถ€ํ„ฐ ์šฐ๋ฆฌ๋Š” ์—ฌ๊ธฐ์— ์žˆ๋Š” ๊ฐ’๋“ค์„ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ด์„œ HTML ๋ฆฌ์ŠคํŠธ๋กœ ๋‚˜ํƒ€๋‚ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋ณต๋ฌธ์„ ์ด์šฉํ•ด์„œ ๋ง์ด์ฃ .

์—ฌ๊ธฐ์— ์žˆ๋Š” ๋ชจ๋“  ์›์†Œ๋“ค์„ writeํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” 3๋ฒˆ์˜ ๋ฐ˜๋ณต์ด ํ•„์š”ํ•  ๊ฒ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ 3๋ฒˆ ๋ฐ˜๋ณตํ•  ์ˆ˜ ์žˆ๋Š” while๋ฌธ์„ ์‚ฌ์šฉํ•ด๋ด…์‹œ๋‹ค.

var i = 0;
while (i < 3) {
  document.write('<li></li>');
  i = i + 1;
}

๊ทธ๋Ÿผ ์ด์ œ li ํƒœ๊ทธ ์‚ฌ์ด์— ๊ฐ๊ฐ์˜ ์›์†Œ๋ฅผ ๋„ฃ์–ด๋ด…์‹œ๋‹ค. ์ด ๋•Œ ์ด i๋ผ๋Š” ๋ณ€์ˆ˜๊ฐ€ 0๋ถ€ํ„ฐ 2๊นŒ์ง€ ๋ฐ”๋€Œ๊ธฐ ๋•Œ๋ฌธ์—, i๋ฅผ ์ž˜ ํ™œ์šฉํ•˜๋ฉด ๋ฐฐ์—ด์—์„œ ์›์†Œ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ผ ์ˆ˜ ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค. ๋ฐ”๋กœ ์ด๋ ‡๊ฒŒ ๋ง์ด์ฃ .

var i = 0;
while (i < 3) {
  document.write('<li>'+fruits[i]+'</li>');
  i = i + 1;
}

ํ•˜์ง€๋งŒ ์—ฌ๊ธฐ์—์„œ ์šฐ๋ฆฌ๊ฐ€ fruits๋ผ๋Š” ๋ฐฐ์—ด ์•ˆ์— "durian"์ด๋ผ๋Š” ์›์†Œ๋ฅผ ํ•˜๋‚˜ ๋” ์ถ”๊ฐ€ํ–ˆ๋‹ค๊ณ  ํ•ด ๋ด…์‹œ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์ด ๋ฐ˜๋ณต๋ฌธ์€ 4๋ฒˆ ์‹คํ–‰๋˜์–ด์•ผ ๋๊นŒ์ง€ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๊ฒ ์ฃ . ํ•˜์ง€๋งŒ ์ง€๊ธˆ์€ 3์œผ๋กœ ์„ค์ •๋˜์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์— durian์ด ์ถœ๋ ฅ๋˜์ง€ ์•Š์„ ๊ฒ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์ด๋ฅผ ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”?

3 ๋Œ€์‹  fruits๋ผ๋Š” ๋ฐฐ์—ด์˜ ๊ธธ์ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋ฉด fruits๋ผ๋Š” ๋ฐฐ์—ด์— ์›์†Œ๊ฐ€ ์ถ”๊ฐ€๋˜๊ฑฐ๋‚˜ ์‚ญ์ œ๋˜์–ด๋„ ์ž๋™์œผ๋กœ ๋ฐ˜๋ณต ํšŸ์ˆ˜๊ฐ€ ์กฐ์ •๋  ๊ฒ๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋˜๊ฒ ์ฃ .

var i = 0;
while (i < fruits.length) {
  document.write('<li>'+fruits[i]+'</li>');
  i = i + 1;
}

์ •๋ฆฌํ•˜์ž๋ฉด, ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜๋ฉด ์ˆœ์„œ๋Œ€๋กœ ์—ฐ๊ด€๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๊ณ , ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉํ•˜๋ฉด ์ˆœ์„œ๋Œ€๋กœ ์ด ๋ฐฐ์—ด์˜ ์›์†Œ๋ฅผ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ด์„œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด ๋‘˜์„ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋ฉด ์•„์ฃผ ์ข‹๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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

๋ฐ˜๋ณต๋ฌธ๊ณผ ๋ฐฐ์—ด์„ ์ ์ ˆํžˆ ํ™œ์šฉํ•ด์„œ fruits ๋ฐฐ์—ด์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆซ์ž์™€ ํ•จ๊ป˜ ์ถœ๋ ฅํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ์ง€ ์ƒ๊ฐํ•ด๋ณด์„ธ์š”.

1. apple 2. banana 3. coconut

<!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>
    <h3>for loop</h3>
    <script>
        var fruits = ['apple', 'banana', 'coconut'];
        for (var i = 0; i < fruits.length; i++) {
            document.write(i + 1 + '. ' + fruits[i] + '<br>');
        }
    </script>
    
    <h3>while loop</h3>
    <ol>
        <script>
            var i = 0;
            while (i < fruits.length) {
                document.write('<li>' + fruits[i] + '</li>');
                i++;
            }
        </script>
    </ol>
</body>

</html>


๋ฐฐ์—ด๊ณผ ๋ฐ˜๋ณต๋ฌธ์˜ ํ™œ์šฉ

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

 

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

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

www.boostcourse.org

๋ฐ˜๋ณต๋ฌธ๊ณผ ๋ฐฐ์—ด์˜ ํ™œ์šฉ

์ด๋ฒˆ ๊ฐ•์˜์—์„œ๋Š” night/day ๋ชจ๋“œ ์˜ˆ์ œ์—์„œ ํ•˜์ดํผ๋งํฌ ๋ถ€๋ถ„์˜ ์ƒ‰๊น”์ด ๋ชจ๋“œ์— ๋”ฐ๋ผ์„œ ๋ฐ”๋€Œ๋„๋ก ๋งŒ๋“ค์–ด ๋ด…์‹œ๋‹ค. ์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์šด ๋ฐ˜๋ณต๋ฌธ๊ณผ ๋ฐฐ์—ด์„ ํ™œ์šฉํ•ด์„œ ๋ง์ด์ฃ .

๋จผ์ € ์ด ํŽ˜์ด์ง€์— ์žˆ๋Š” ๋ชจ๋“  a ํƒœ๊ทธ๋ฅผ ๊ฐ€์ ธ์™€์•ผ๊ฒ ์ฃ . ์›๋ž˜ ์‚ฌ์šฉํ•˜๋˜ querySelector๋ผ๋Š” ํ•จ์ˆ˜๋Š” ํ•˜๋‚˜์˜ ํƒœ๊ทธ๋งŒ ์•Œ๋ ค์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ์ƒˆ๋กœ์šด ํ•จ์ˆ˜๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋ฐ”๋กœ querySelectorAll์ด๋ผ๋Š” ํ•จ์ˆ˜์ฃ . ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

var alist = document.querySelectorAll('a');

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด querySelectorAll์ด ์ฐพ์€ ๋ชจ๋“  a ํƒœ๊ทธ๋ฅผ ๋ฐฐ์—ด ํ˜•ํƒœ๋กœ alist์— ์ €์žฅํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

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

var i = 0;
while (i < alist.length) {

}

์ด์ œ ์ด while๋ฌธ ์•ˆ์— ๊ฐ๊ฐ์˜ ์Šคํƒ€์ผ์„ ์ง€์ •ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๋„ฃ์–ด์ฃผ๋„๋ก ํ•ฉ์‹œ๋‹ค. ๋จผ์ € alist์˜ i๋ฒˆ์งธ ์›์†Œ๋ฅผ ๊ฐ€์ ธ์˜ค๋ฉด ๋˜๊ฒ ์ฃ . ๊ทธ๋ฆฌ๊ณ  ์ด๋ ‡๊ฒŒ ๊ฐ€์ ธ์˜จ ํƒœ๊ทธ์˜ ์Šคํƒ€์ผ์„ ์ง€์ •ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋งˆ์ง€๋ง‰์— i์— 1์„ ๋”ํ•ด์ฃผ๋Š” ๊ฒƒ๋„ ์žŠ์œผ๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

var i = 0;
while (i < alist.length) {
  alist[i].style.color = 'powderblue';
  i = i + 1;
}

์ด ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ด๋ณด๋ฉด ๋ฌธ์„œ ์•ˆ์˜ ๋ชจ๋“  a ํƒœ๊ทธ์˜ ์ƒ‰๊น”์ด powderblue๋กœ ๋ฐ”๋€Œ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ์™„์„ฑํ•œ ์ฝ”๋“œ๋ฅผ if๋ฌธ ์•ˆ์— ๋„ฃ์–ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋ฌผ๋ก  night ๋ชจ๋“œ์—์„œ day ๋ชจ๋“œ๋กœ ๋ฐ”๋€” ๋•Œ์—๋Š” powderblue๋Œ€์‹  blue๋ฅผ ์จ์ฃผ์–ด์•ผ๊ฒ ์ฃ ?

์ €๋Š” pink๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํ•œ๋ฒˆ ์ฝ”๋“œ๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

<!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="">
    <a href="WEB.html" style="font-size: 30px;">WEB</a><br>
    <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'
        
        var alist = document.querySelectorAll('a')
        var i = 0;
            while(i<alist.length){
            alist[i].style.color = 'pink';
            i++;
            }
    }
    else{
        target.style.backgroundColor = 'white';
        target.style.color = 'black';
        this.value = 'night'

        var alist = document.querySelectorAll('a')
        var i = 0;
            while(i<alist.length){
            alist[i].style.color = 'blue';
            i++;
            }
    }
    ">

    <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>
    <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'
    }
    ">
</body>

</html>

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

์ด๋ฒˆ ๊ฐ•์˜์—์„œ ๋ฐฐ์šด ์ฝ”๋“œ๋ฅผ ์•ฝ๊ฐ„ ์ˆ˜์ •ํ•ด์„œ ์ฒซ ๋ฒˆ์งธ ํ•˜์ดํผ๋งํฌ๋ฅผ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ์„ธ ๊ฐœ์˜ ํ•˜์ดํผ๋งํฌ๋งŒ ์ƒ‰๊น”์ด ๋ฐ”๋€Œ๋„๋ก ๋งŒ๋“ค์–ด๋ณด์„ธ์š”.

 

๋ฐฐ์—ด์˜ ์‹œ์ž‘์„ 1๋ถ€ํ„ฐ ์‹œ์ž‘์„ ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

var i = 1;
            while(i<alist.length){
            alist[i].style.color = 'blue';
            i++;
            }

ํ€ด์ฆˆ๋„ ์†์‰ฝ๊ฒŒ ์„ฑ๊ณต~! 


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.