|
写経練習
2026年1月18日(日) 11時45分
以下をメモ帳に入力して拡張子.txtで保存しよう! // 1. 正解の数字を決める(1〜10) let answer = Math.floor(Math.random() * 10) + 1; let count = 0; // 2. ボタンが押された時の処理 function checkGuess() { let input = prompt("1から10の数字を入れてね!"); let guess = parseInt(input); count++; if (guess === answer) { alert("正解!" + count + "回目で当てたね!"); // 正解したのでリセット answer = Math.floor(Math.random() * 10) + 1; count = 0; } else if (guess > answer) { alert("もっと小さいよ!"); } else { alert("もっと大きいよ!"); } } checkGuess();
|