Open2

JavaScript学習記録4

ミワミワ

section_1 for文による繰り返し

t5_1.js
console.log("つみトレ5章: SECTION_01");
console.log("for文による繰り返し");

// c5_1_1.js
for(let i = 0; i <3; i++) {
    console.log('ペテロはイエスを知らないと言う', i);
}
console.log('ニワトリが鳴く');
t5_1.js
// c5_1_2.js
let targets = ['マトA','マトB','マトC'];
for (let i = 0; i <3; i++){
    console.log(`${targets[i]}に手裏剣を投げた`);
}
t5_1.js
// c5_1_3.js
let targets2 = ['マトA','マトB','マトC'];
for (let target of targets2){
    console.log(`${target}に手裏剣を投げた`);
}
t5_1.js
// c5_1_4.js
let consonants = ['','k','s','t','n'];
let vowels = ['a','i','u','e','o'];
for (let consonant of consonants){
    for (let vowel of vowels){
        console.log(`${consonant}${vowel}`);
    }
}
ミワミワ

section_2 while文による繰り返し

t5_2.js
console.log("つみトレ5章: SECTION_02");
console.log("while文による繰り返し");

// c5_2_1.js
let password = '';
while (password !== '川'){
    password = prompt('山?:');
}
console.log('入れ');
t5_2.js
// c5_2_2.js
do {
    console.log('せめて一度だけでも');
}
while(false)
t5_2.js
// c5_2_3.js 注:(元)無限ループコード
let tsumami = 'shiokara';
while (tsumami !== ''){
    console.log('sake');
    console.log(tsumami);
    //無限ループ回避
    tsumami = ''
}