-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #434 from ut-code/change-var-name-in-function-exer…
…cise Change the name of variable in med. exercise in loop
- Loading branch information
Showing
3 changed files
with
30 additions
and
30 deletions.
There are no files selected for viewing
14 changes: 7 additions & 7 deletions
14
docs/1-trial-session/08-loop/_samples/is-prime-using-and/script.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
let integer = 89; //任意の整数 | ||
let n = 89; //任意の整数 | ||
|
||
let isPrime = true; | ||
if (integer <= 1) { | ||
if (n <= 1) { | ||
isPrime = false; | ||
} | ||
|
||
for (let i = 2; i < integer; i += 1) { | ||
// integerが1以下のときは素数でない | ||
isPrime = isPrime && integer % i != 0; | ||
for (let i = 2; i < n; i += 1) { | ||
// nが1以下のときは素数でない | ||
isPrime = isPrime && n % i != 0; | ||
} | ||
|
||
if (isPrime) { | ||
document.write(`${integer} は素数です。`); | ||
document.write(`${n} は素数です。`); | ||
} else { | ||
document.write(`${integer} は素数ではありません。`); | ||
document.write(`${n} は素数ではありません。`); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
let integer = 57; // 任意の整数 | ||
let n = 57; // 任意の整数 | ||
|
||
let isPrime = true; | ||
if (integer <= 1) { | ||
// integerが1以下のときは素数でない | ||
if (n <= 1) { | ||
// nが1以下のときは素数でない | ||
isPrime = false; | ||
} | ||
|
||
for (let i = 2; i < integer; i += 1) { | ||
if (integer % i == 0) { | ||
for (let i = 2; i < n; i += 1) { | ||
if (n % i == 0) { | ||
isPrime = false; // 変数には最後に代入した値のみを保持する | ||
} | ||
} | ||
|
||
if (isPrime) { | ||
document.write(`${integer} は素数です`); | ||
document.write(`${n} は素数です`); | ||
} else { | ||
document.write(`${integer} は素数ではありません`); | ||
document.write(`${n} は素数ではありません`); | ||
} |
This file contains 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