Skip to content

Instantly share code, notes, and snippets.

@Kkan9ma
Created July 8, 2019 03:12
Show Gist options
  • Save Kkan9ma/aad956e62eb8c87c92a06855f49d1433 to your computer and use it in GitHub Desktop.
Save Kkan9ma/aad956e62eb8c87c92a06855f49d1433 to your computer and use it in GitHub Desktop.
<!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>
function calculate(x) {
var result = [];
for (var i = 1; i <= 9; i++) {
result[i] = x * i;
}
return result;
};
function printResult(x, result) {
document.write("<h2>" + x + "단</h2>");
for (var i = 1; i <= 9; i++) {
document.write(x + " * " + i + " = " + result[i] + "<br>")
}
};
function main() {
console.log("main function run")
for (var i = 2; i <= 9; i++) {
var ret = calculate(i);
printResult(i, ret);
}
};
main();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment