사용자가 올바른 번호를 추측하면 사용자가 다시 게임을 할 것인지 물어볼 필요가 있습니다. 루프가 그대로 반복 될 것이지만 내가 원하는 것은 다시 연주하고 싶으면 묻는 프롬프트 상자입니다. 사용자가 예라고 대답하면 대답이 추측 될 때까지 루프가 다시 시작됩니다.자바 스크립트 초보자 : 루프를 다시 시작하는 방법
<HTML>
<HEAD>
</HEAD>
<BODY
<FORM NAME="testform">
<BR>
<BR>
<BR>
</FORM>
<INPUT id="attempts" TYPE="text" NAME="inputbox" VALUE="" />
<INPUT id="zero" TYPE="button" NAME="resetbox" VALUE="Reset " onclick="reset()" />
<SCRIPT type="text/javascript">
varattempts = 0;
x = Math.round((Math.random()*19))+1;
var tip;
tip=prompt("Do you want to play a game?")
while(tip.charAt(0).toLowerCase() == "y")
{
var Guess;
document.getElementById('attempts').value = 0;
do
{
Guess = prompt("Pick a number between 1 and 20","")
if (Guess === null) break;
document.getElementById('attempts').value = parseInt(document.getElementById('attempts').value)+1
} while (Guess!=x);
if (Guess == x)
{
alert("You guessed right!")
}
}
function reset()
{
varattempts=0;
document.getElementById('attempts').value = 'Attempts: 0';
}
</SCRIPT>
</BODY>
</HTML>
나는 책에서이 장을 다시 읽을 것입니다. – Loktar
이 숙제가 있습니까? – icktoofay
'varattempts = 0;'은 오타처럼 보입니다. –