﻿ 猜數_電腦知識網

# 猜數

2022-06-13   來源: JSP教程

腳本說明:

<SCRIPT LANGUAGE=JavaScript>
var js_mult=
var js_mult=
var js_m=
var js_m=
var js_iseed=
var js_iseed=
var js_iseed=
function random(n)
{
if (js_iseed == )
{
now = new Date()
js_iseed = nowgetHours() + nowgetMinutes() *
+ nowgetSeconds() *
}
js_iseed = js_iseed / js_m
js_iseed = js_iseed % js_m
var tmp = (((js_iseed * js_mult + js_iseed * js_mult) % js_m) *
js_m + (js_iseed * js_mult)) % js_m
js_iseed = (tmp + ) % js_m
return (Mathfloor((js_iseed/js_m) * n))
}
var myNumber =
var nGuesses =
function guessnum()
{
var response
var num = parseInt(documentforms[]guessvalue)
documentforms[]guessvalue = num // visual feedback in case of NaN
nGuesses++ // increase the guess count
response = 你猜的數
if (num < myNumber)    response = response + 太小了
if (num > myNumber)    response = response + 太大了
if (num == myNumber)
{
response = response + 對了！！你猜到我了！
nGuesses =
myNumber = random()+
}
documentforms[]resultvalue=response
documentforms[]guessesvalue=nGuesses
documentforms[]guessfocus()
documentforms[]guessselect()
return true
}
function giveup()
{
var response
nGuesses =
response = 我的數字是 + myNumber +  想猜我的新數嗎？
myNumber = random()+
documentforms[]resultvalue=response
documentforms[]guessesvalue=nGuesses
documentforms[]guessfocus()
documentforms[]guessselect()
}
</SCRIPT>

<font size= color=#FF>

</font>
<SCRIPT>
myNumber = random()+
nGuesses =
</SCRIPT>
<FORM onSubmit=guessnum(); return false>

<INPUT TYPE=button VALUE=     我來猜   onClick=guessnum()
<INPUT TYPE=button VALUE=  放棄  onClick=giveup()
</FORM>
<FORM>

</FORM>

第二步:把<body>區域中的內容改為: