Skip to content

Commit 8e97e3b

Browse files
authored
Merge pull request #405 from ut-code/updated-add-more-prac-exercise-from-loop-to-array
loop ~ arrayの演習問題の追加、再配置
2 parents d62aa45 + 52b55a9 commit 8e97e3b

File tree

33 files changed

+712
-102
lines changed

33 files changed

+712
-102
lines changed

docs/1-trial-session/08-loop/_samples/answer-while/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="ja">
33
<head>
44
<meta charset="utf-8" />
5-
<title>課題の解答</title>
5+
<title>確認問題の解答</title>
66
</head>
77
<body>
88
<script src="./script.js"></script>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>素数判定問題の解答例 (帰納的解法)</title>
6+
</head>
7+
<body>
8+
<script src="./script.js"></script>
9+
</body>
10+
</html>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let n = 89; //任意の整数
2+
3+
let isPrime = true;
4+
if (n <= 1) {
5+
isPrime = false;
6+
}
7+
8+
for (let i = 2; i < n; i += 1) {
9+
// nが1以下のときは素数でない
10+
isPrime = isPrime && n % i != 0;
11+
}
12+
13+
if (isPrime) {
14+
document.write(`${n} は素数です。`);
15+
} else {
16+
document.write(`${n} は素数ではありません。`);
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>素数判定問題の解答例</title>
6+
</head>
7+
<body>
8+
<script src="./script.js"></script>
9+
</body>
10+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
let n = 57; // 任意の整数
2+
3+
let isPrime = true;
4+
if (n <= 1) {
5+
// nが1以下のときは素数でない
6+
isPrime = false;
7+
}
8+
9+
for (let i = 2; i < n; i += 1) {
10+
if (n % i == 0) {
11+
isPrime = false; // 変数には最後に代入した値のみを保持する
12+
}
13+
}
14+
15+
if (isPrime) {
16+
document.write(`${n} は素数です`);
17+
} else {
18+
document.write(`${n} は素数ではありません`);
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>積の演習の解答例 (複合演算子)</title>
6+
</head>
7+
<body>
8+
<script src="./script.js"></script>
9+
</body>
10+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let product = 1;
2+
3+
for (let i = 1; i <= 10; i += 1){
4+
product *= i;
5+
}
6+
7+
document.write(product);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>積の演習の解答例</title>
6+
</head>
7+
<body>
8+
<script src="./script.js"></script>
9+
</body>
10+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let product = 1;
2+
3+
for (i = 1; i <= 10; i = i + 1) {
4+
product = product * i;
5+
}
6+
7+
document.write(product);

docs/1-trial-session/08-loop/_samples/times-table/script.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)