Created
July 8, 2019 03:20
-
-
Save Kkan9ma/9cfd07a0720639a4ee53114798e9edd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Gugudan</title> | |
</head> | |
<body> | |
<h1>구구단 객체로 구현하기</h1> | |
<script> | |
var gugudan = {}; | |
gugudan.results = []; | |
gugudan.num = -1; // 단수 메소드, -1로 초기화 | |
gugudan.Calculate = function(x) { | |
this.num = x; | |
for (var i = 0; i < 9; i++) { | |
this.results[i] = this.num * (i + 1); | |
} | |
} | |
gugudan.printResult = function() { | |
document.write("<h2>" + this.num +"단</h2>"); | |
for (var i = 0; i < 9; i++) { | |
document.write(this.num + " * " + (i + 1) + " = " + this.results[i] + "<br>"); | |
} | |
} | |
function main() { | |
console.log("main 함수가 실행되었습니다."); | |
for (var i = 2; i < 9; i++) { | |
gugudan.Calculate(i); | |
gugudan.printResult(); | |
} | |
} | |
main(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment