Bibi's DevLog ๐Ÿค“๐ŸŽ

[์ธํ”„๋Ÿฐ] Javascript์ž…๋ฌธ - 4,5๋‹จ ๊ตฌํ˜„(๊ฐ’ ์ž…๋ ฅ ๋ฐ ๋ณ€์ˆ˜) & ์ฝ”๋”ฉ ๊ตฌํ˜„ ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Javascript ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ

[์ธํ”„๋Ÿฐ] Javascript์ž…๋ฌธ - 4,5๋‹จ ๊ตฌํ˜„(๊ฐ’ ์ž…๋ ฅ ๋ฐ ๋ณ€์ˆ˜) & ์ฝ”๋”ฉ ๊ตฌํ˜„

๋น„๋น„ bibi 2020. 10. 7. 16:54
* ์ด ๊ธ€์€ ์ธํ”„๋Ÿฐ์—์„œ ์ œ๊ณตํ•˜๋Š” ํ˜ธ๋ˆ…์Šค๋‹˜์˜ ์œ ๋ฃŒ ๊ฐ•์˜ '์‰ฝ๊ณ  ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ฐฐ์›Œ๋ณด๋Š” Javascript ์ž…๋ฌธ - ์ฝ”๋“œ์Šค์ฟผ๋“œ ๋งˆ์Šคํ„ฐ์ฆˆ ์ฝ”์Šค ๋ ˆ๋ฒจ1'๋ฅผ ๋“ฃ๊ณ  ๊ณต๋ถ€ํ•˜๋ฉฐ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ๊ฐ•์˜ ๋‚ด์šฉ์— ๋”ํ•ด, ์ œ๊ฐ€ ํ•„๊ธฐํ•˜๊ณ  ๊ตฌ๊ธ€๋งํ•œ ๋‚ด์šฉ์ด ์ •๋ฆฌ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ดˆ๋ณด์ธ ์ œ๊ฐ€ ์ดํ•ดํ•œ ๋Œ€๋กœ ์ •๋ฆฌํ–ˆ๊ธฐ ๋•Œ๋ฌธ์—, ๋ถ€์ •ํ™•ํ•œ ๋‚ด์šฉ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Œ์„ ๊ฐ์•ˆํ•ด ์ฃผ์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๊ฐ•์˜๋ฅผ ๋“ฃ๊ณ  ๋‚ด์šฉ์„ ์ •๋ฆฌํ•œ ๊ธ€์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์ธํ”„๋Ÿฐ ์ธก ๋‹ต๋ณ€์„ ๋ฐ›์€ ์ ์ด ์žˆ์œผ๋‚˜(https://bibi6666667.tistory.com/37), ์ €์ž‘๊ถŒ์ƒ ๋ฌธ์ œ๊ฐ€ ๋œ๋‹ค๋ฉด ๋ณดํ˜ธ ๋ชจ๋“œ(๋น„๊ณต๊ฐœ)๋กœ ์ „ํ™˜ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

ํ•™์Šต ๋ชฉํ‘œ

  • ๋ณ€์ˆ˜๋ฅผ ๊ฒฝํ—˜ํ•œ๋‹ค.
  • ์˜์–ด ํƒ€์ดํ•‘์„ ์—ฐ์Šตํ•œ๋‹ค.
  • ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณธ๋‹ค.

์š”๊ตฌ์‚ฌํ•ญ

  • ๊ตฌ๊ตฌ๋‹จ์—์„œ 4๋‹จ๊ณผ 5๋‹จ์„ ๊ณ„์‚ฐํ•œ ๊ฒฐ๊ณผ ๊ฐ’์„ ๋ณ€์ˆ˜์— ์ €์žฅํ•œ ํ›„ ์ €์žฅํ•œ ๋ณ€์ˆ˜ ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.
  • 4์™€ 5๋Š” ๊ฒฐ์ •ํ•˜๋ฉด ๋ฐ”๋€Œ์ง€ ์•Š๋Š” ๊ฐ’์ด๋‹ค. ๋”ฐ๋ผ์„œ 4๋‹จ๊ณผ 5๋‹จ์— ํ•ด๋‹นํ•˜๋Š” ์ƒ์ˆ˜ ๊ฐ’์œผ๋กœ ๋งŒ๋“  ํ›„ ํ”„๋กœ๊ทธ๋žจ์„ ๊ตฌํ˜„ํ•œ๋‹ค.
  • ์˜ˆ๋ฅผ ๋“ค์–ด 4๋‹จ์€ 4 ๊ณฑํ•˜๊ธฐ 1 ๊ณ„์‚ฐ ๊ฒฐ๊ณผ ๊ฐ’์„ i๋ผ๋Š” ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๊ณ , i๋ผ๋Š” ๋ณ€์ˆ˜์— ์ €์žฅํ•œ ๊ฒฐ๊ณผ ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.
  • ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ์ˆซ์ž ๊ฐ’์— ํ•ด๋‹นํ•˜๋Š” ๋‹จ์„ ์ถœ๋ ฅํ•œ๋‹ค.
    • ์˜ˆ๋ฅผ ๋“ค์–ด ์‚ฌ์šฉ์ž๊ฐ€ 4๋ผ๋Š” ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜๋ฉด 4๋‹จ ์ „์ฒด๋ฅผ ๊ณ„์‚ฐํ•ด ์ถœ๋ ฅํ•œ๋‹ค.
  • ์ฝ˜์†” ๋ฒ„์ „๊ณผ ์›น ๋ฒ„์ „ ๋‘ ๊ฐœ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.

๊ฒฐ๊ณผ๋ฌผ

  • gugudan3.html
  • gugudan4.html
  • ๋‘ ์ฝ”๋“œ๋ฅผ ์ปค๋ฐ‹ํ•œ ๊นƒํ—ˆ๋ธŒ ์ €์žฅ์†Œ ๋งํฌ

ํžŒํŠธ

  • ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€์ˆ˜์— ๊ฐ’์„ ์ €์žฅํ•˜๊ณ  ์ถœ๋ ฅํ•œ๋‹ค.
var result; 
result = 4 * 1; 
console.log(result);
  • 4๋‹จ์„ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ 4๋ผ๋Š” ๊ฐ’์€ ๋ณ€ํ•˜์ง€ ์•Š๋Š”๋‹ค. 4๋ผ๋Š” ๊ฐ’์„ ๋ณ€์ˆ˜๋กœ ๋งŒ๋“ ๋‹ค.
var num4 = 4; 
var result = num4 * 1;
  • ์‚ฌ์šฉ์ž์—๊ฒŒ ์ˆซ์ž ๊ฐ’์„ ์ž…๋ ฅ ๋ฐ›๋Š” ๋ฐฉ๋ฒ•
var num = prompt("๋ช‡ ๋‹จ์„ ์ถœ๋ ฅํ•˜์‹ค ๊ฑด๊ฐ€์š”?");
console.log(num);

 

ํ•™์Šต ์ฐธ๊ณ  ์ž๋ฃŒ 

: ์ƒํ™œ์ฝ”๋”ฉ -WEB2 JavaScript - 7.๋ณ€์ˆ˜์™€ ๋Œ€์ž… ์—ฐ์‚ฐ์ž.

https://youtu.be/absJhWQAS40

 

๋ณด๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ : bibi6666667.tistory.com/59

 

์ฐธ์กฐ ๊ฐ•์ขŒ ) ์ƒํ™œ์ฝ”๋”ฉ -WEB2 JavaScript - 7.๋ณ€์ˆ˜์™€ ๋Œ€์ž… ์—ฐ์‚ฐ์ž.

โ€ป ์ด ๋ฌธ์„œ๋Š” bibi6666667.tistory.com/55์˜ ์ฐธ์กฐ ๋ฌธ์„œ์ž…๋‹ˆ๋‹ค. [์ธํ”„๋Ÿฐ] Javascript์ž…๋ฌธ - 4,5๋‹จ ๊ตฌํ˜„(๊ฐ’ ์ž…๋ ฅ ๋ฐ ๋ณ€์ˆ˜) & ์ฝ”๋”ฉ ๊ตฌํ˜„ ๋น„๋น„์˜ ์ดˆ์› Bibi's grasslandโ›บ [์ธํ”„๋Ÿฐ] Javascript์ž…๋ฌธ - 4,5๋‹จ ๊ตฌํ˜„(๊ฐ’ ์ž…..

bibi6666667.tistory.com


์ฝ”๋”ฉ ๊ตฌํ˜„

 

๋‚ด๊ฐ€ ํ‘ผ ์ฝ”๋“œ

gugudan3.html (์ฝ˜์†” ๋ฒ„์ „)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>๊ตฌ๊ตฌ๋‹จ 4๋‹จ, 5๋‹จ - ์ฝ˜์†” ๋ฒ„์ „</h2>
<script>
    var num = Number(prompt('๊ตฌ๊ตฌ๋‹จ 4๋‹จ์ด๋‚˜ 5๋‹จ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. 4๋‹จ์€ "4", 5๋‹จ์€ "5"๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”'));
    var result = num * 1
    if (num === 4){
        console.log(num + ' * 1 = ' + (num * 1));
        console.log(num + ' * 2 = ' + (num * 2));
        console.log(num + ' * 3 = ' + (num * 3));
        console.log(num + ' * 4 = ' + (num * 4));
        console.log(num + ' * 5 = ' + (num * 5));
        console.log(num + ' * 6 = ' + (num * 6));
        console.log(num + ' * 7 = ' + (num * 7));
        console.log(num + ' * 8 = ' + (num * 8));
        console.log(num + ' * 9 = ' + (num * 9));
    } else if (num === 5){
        console.log(num + ' * 1 = ' + (num * 1));
        console.log(num + ' * 2 = ' + (num * 2));
        console.log(num + ' * 3 = ' + (num * 3));
        console.log(num + ' * 4 = ' + (num * 4));
        console.log(num + ' * 5 = ' + (num * 5));
        console.log(num + ' * 6 = ' + (num * 6));
        console.log(num + ' * 7 = ' + (num * 7));
        console.log(num + ' * 8 = ' + (num * 8));
        console.log(num + ' * 9 = ' + (num * 9));
    } else {
        console.log('์ด ํŽ˜์ด์ง€์—์„œ๋Š” 4๋‹จ๊ณผ 5๋‹จ๋งŒ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.')
    }
</script>
</body>
</html>

 

gugudan4.html (์›น ๋ฒ„์ „)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>๊ตฌ๊ตฌ๋‹จ 4๋‹จ, 5๋‹จ - ์ฝ˜์†” ๋ฒ„์ „</h2>
<script>
    var num = Number(prompt('๊ตฌ๊ตฌ๋‹จ 4๋‹จ์ด๋‚˜ 5๋‹จ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. 4๋‹จ์€ "4", 5๋‹จ์€ "5"๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”'));
    if (num === 4){
        document.write(num + ' * 1 = ' + (num * 1)+'<br>');
        document.write(num + ' * 2 = ' + (num * 2)+'<br>');
        document.write(num + ' * 3 = ' + (num * 3)+'<br>');
        document.write(num + ' * 4 = ' + (num * 4)+'<br>');
        document.write(num + ' * 5 = ' + (num * 5)+'<br>');
        document.write(num + ' * 6 = ' + (num * 6)+'<br>');
        document.write(num + ' * 7 = ' + (num * 7)+'<br>');
        document.write(num + ' * 8 = ' + (num * 8)+'<br>');
        document.write(num + ' * 9 = ' + (num * 9)+'<br>');
    } else if (num === 5){
        document.write(num + ' * 1 = ' + (num * 1)+'<br>');
        document.write(num + ' * 2 = ' + (num * 2)+'<br>');
        document.write(num + ' * 3 = ' + (num * 3)+'<br>');
        document.write(num + ' * 4 = ' + (num * 4)+'<br>');
        document.write(num + ' * 5 = ' + (num * 5)+'<br>');
        document.write(num + ' * 6 = ' + (num * 6)+'<br>');
        document.write(num + ' * 7 = ' + (num * 7)+'<br>');
        document.write(num + ' * 8 = ' + (num * 8)+'<br>');
        document.write(num + ' * 9 = ' + (num * 9)+'<br>');
    } else {
        document.write('์ด ํŽ˜์ด์ง€์—์„œ๋Š” 4๋‹จ๊ณผ 5๋‹จ๋งŒ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.')
    }
</script>
</body>
</html>

 

 

์˜ค๋‹ต๋…ธํŠธ

์ •๋‹ต

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>๊ตฌ๊ตฌ๋‹จ - ์›น ๋ฒ„์ „(์ •๋‹ต)</h2>
<script>
    var num = Number(prompt('๊ตฌ๊ตฌ๋‹จ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ์›ํ•˜๋Š” ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”'));
    document.write("<h4>๊ตฌ๊ตฌ๋‹จ"+ num +"๋‹จ</h4>")
    document.write(num + ' * 1 = ' + (num * 1)+'<br>');
    document.write(num + ' * 2 = ' + (num * 2)+'<br>');
    document.write(num + ' * 3 = ' + (num * 3)+'<br>');
    document.write(num + ' * 4 = ' + (num * 4)+'<br>');
    document.write(num + ' * 5 = ' + (num * 5)+'<br>');
    document.write(num + ' * 6 = ' + (num * 6)+'<br>');
    document.write(num + ' * 7 = ' + (num * 7)+'<br>');
    document.write(num + ' * 8 = ' + (num * 8)+'<br>');
    document.write(num + ' * 9 = ' + (num * 9)+'<br>');

</script>
</body>
</html>

- ๊ตณ์ด if๋ฌธ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ. 4๋‹จ๊ณผ 5๋‹จ๋งŒ์ด ์•„๋‹Œ ๋ชจ๋“  ์ˆซ์ž์˜ ๊ตฌ๊ตฌ๋‹จ ๊ฐ€๋Šฅ.
- ๊ตฌ๊ตฌ๋‹จ n๋‹จ ์ด๋ผ๋Š” ์†Œ์ œ๋ชฉ ์ถ”๊ฐ€.