Last active
April 29, 2025 00:25
-
-
Save sdkfz181tiger/73985bbdaaee89c01b9cde939f9b8a17 to your computer and use it in GitHub Desktop.
JavaScript_定番ハンズオン7選_2025
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
console.log("main.js!!"); | |
const inputName = prompt("名前を入力してください"); | |
console.log("こんにちは,", inputName, "さん!!"); | |
const inputAge = prompt("年齢を入力してください"); | |
console.log("年齢は,", inputAge, "ですね"); | |
const numAge = parseInt(inputAge); | |
if(numAge < 13){ | |
console.log("少年です!!"); | |
}else if(numAge < 18){ | |
console.log("青年です!!"); | |
}else if(numAge < 30){ | |
console.log("成人です!!"); | |
}else if(numAge < 65){ | |
console.log("中年です!!"); | |
}else{ | |
console.log("高齢です!!"); | |
} | |
const inputSum = prompt("数字をを入力してください"); | |
console.log("1 ~", inputSum, "までの合計値を計算します"); | |
const numSum = parseInt(inputSum); | |
let numTotal = 0; | |
for(let i=0; i<numSum; i++){ | |
numTotal += i + 1; | |
} | |
console.log("合計値は", numTotal, "です"); |
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
console.log("main.js!!"); | |
//========== | |
// サイコロ | |
const rdm = Math.random() * 5; | |
const num = Math.floor(rdm) + 1; | |
console.log("サイコロ: ", num); | |
const showDice = (num)=>{ | |
if(num == 1){ | |
console.log("+-------+"); | |
console.log("| |"); | |
console.log("| ● |"); | |
console.log("| |"); | |
console.log("+-------+"); | |
return; | |
} | |
if(num == 2){ | |
console.log("+-------+"); | |
console.log("| ● |"); | |
console.log("| |"); | |
console.log("| ● |"); | |
console.log("+-------+"); | |
return; | |
} | |
if(num == 3){ | |
console.log("+-------+"); | |
console.log("| ● |"); | |
console.log("| ● |"); | |
console.log("| ● |"); | |
console.log("+-------+"); | |
return; | |
} | |
if(num == 4){ | |
console.log("+-------+"); | |
console.log("| ● ● |"); | |
console.log("| |"); | |
console.log("| ● ● |"); | |
console.log("+-------+"); | |
return; | |
} | |
if(num == 5){ | |
console.log("+-------+"); | |
console.log("| ● ● |"); | |
console.log("| ● |"); | |
console.log("| ● ● |"); | |
console.log("+-------+"); | |
return; | |
} | |
if(num == 6){ | |
console.log("+-------+"); | |
console.log("| ● ● |"); | |
console.log("| ● ● |"); | |
console.log("| ● ● |"); | |
console.log("+-------+"); | |
return; | |
} | |
} | |
showDice(num); |
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
console.log("main.js!!"); | |
//========== | |
// おみくじ | |
const rdm = Math.random() * 7; | |
const num = Math.floor(rdm); | |
if(rdm == 0){ | |
console.log("大吉です!!"); | |
}else if(rdm == 1){ | |
console.log("中吉です!!"); | |
}else if(rdm == 2){ | |
console.log("小吉です!!"); | |
}else if(rdm == 3){ | |
console.log("吉です!!"); | |
}else if(rdm == 4){ | |
console.log("末吉です!!"); | |
}else if(rdm == 5){ | |
console.log("凶です!!"); | |
}else{ | |
console.log("大凶です!!"); | |
} |
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
console.log("main.js!!"); | |
//========== | |
// 数字当てゲーム | |
console.log("== 数字当てゲーム =="); | |
let nMin = 0; | |
let nMax = 10; | |
const rdm = Math.random() * (nMax-nMin); | |
const nAnswer = Math.floor(rdm) + nMin; | |
while(true){ | |
const msg = "ヒント: " + nMin + "~" + nMax + " までの範囲です"; | |
const input = prompt(msg); | |
if(input == "q") break; | |
const nInput = parseInt(input); | |
if(Number.isNaN(nInput)) continue; | |
if(nInput < nAnswer){ | |
alert("残念、" + input + "より大きい数字です"); | |
nMin = nInput + 1; | |
continue; | |
} | |
if(nAnswer < nInput){ | |
alert("残念、" + input + "より小さい数字です"); | |
nMax = nInput - 1; | |
continue; | |
} | |
alert("正解です: " + nAnswer) | |
break; | |
} |
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
console.log("main.js!!"); | |
//========== | |
// ピラミッド | |
console.log("== ピラミッド =="); | |
const msg = "高さを入力してください"; | |
const input = prompt(msg); | |
const height = parseInt(input); | |
console.log("高さ: ", height); | |
console.log("Type-A"); | |
for(let r=0; r<height; r++){ | |
let line = ""; | |
for(let c=0; c<r+1; c++){ | |
line += "*"; | |
} | |
console.log(line); | |
} | |
console.log("Type-B"); | |
for(let r=0; r<height; r++){ | |
let line = ""; | |
for(let c=0; c<height-(r+1); c++){ | |
line += "_"; | |
} | |
for(let c=0; c<r+1; c++){ | |
line += "*"; | |
} | |
console.log(line); | |
} | |
console.log("Type-C"); | |
for(let r=0; r<height; r++){ | |
let line = ""; | |
for(let c=0; c<height-(r+1); c++){ | |
line += "_"; | |
} | |
for(let c=0; c<r*2+1; c++){ | |
line += "*"; | |
} | |
console.log(line); | |
} |
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
console.log("main.js!!"); | |
//========== | |
// ジャンケン | |
console.log("== ジャンケン =="); | |
const HANDS = ["グー", "チョキ", "パー"]; | |
const msg = "1: グー, 2: チョキ, 3, パー, q: 終了"; | |
let nWin = 0; | |
let nLose = 0; | |
let nEven = 0; | |
while(true){ | |
const input = prompt(msg); | |
if(input == "q") break; | |
const nYou = parseInt(input); | |
if(Number.isNaN(nYou)) continue; | |
if(nYou < 1 || HANDS.length-1 < nYou) continue; | |
const nCom = Math.floor(Math.random() * HANDS.length) + 1; | |
const vs = "YOU: " + HANDS[nYou-1] + " vs COM: " + HANDS[nCom-1]; | |
const result = (nCom - nYou + 3) % 3; | |
if(result == 1){ | |
alert(vs + " => 勝ちました"); | |
nWin++; | |
}else if(result == 2){ | |
alert(vs + " => 負けました"); | |
nLose++; | |
}else{ | |
alert(vs + " => あいこです"); | |
nEven++; | |
} | |
console.log("成績", "Win(", nWin, "), Lose(", nLose, "), Even(", nEven, ")"); | |
} |
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
console.log("main.js!!"); | |
//========== | |
// タイピングゲーム | |
console.log("== タイピングゲーム =="); | |
const WORDS = ["abc", "def", "ghi", "jkl", "mno"]; | |
const total = WORDS.length; | |
let index = 0; | |
let score = 0; | |
while(true){ | |
const answer = WORDS[index]; | |
const msg = "[問" + (index+1) + "]: " + answer + ", q: 終了"; | |
const input = prompt(msg); | |
if(input == "q") break; | |
if(input == answer){ | |
console.log("GOOD!!"); | |
score++; | |
}else{ | |
console.log("BAD..."); | |
} | |
if(index < total-1){ | |
index++; | |
continue; | |
} | |
break; | |
} | |
alert("結果:" + score + "/" + total + "点"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment