電腦隨機0-9選出3個數字(數字可重複) ex:123, 019
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
<Script type ="text/javascript">
var r1,r2,r3,maxNum,minNum;
var r1=0;
var r2=0;
var r3=0;
maxNum=9;
minNum=0;
r1=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
r2=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
r3=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
document.write("亂數r1:",+r1,"亂數r2:",+r2,"亂數r3:",+r3);
</Script>
</body>
</html>
電腦隨機0-9選出3個數字(數字不重複)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
<Script type ="text/javascript">
var r1,r2,r3,maxNum,minNum;
var r1=0;
var r2=0;
var r3=0;
maxNum=9;
minNum=0;
r1=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
r2=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
r3=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
if(r2==r1)
{r2=r2+1;}
if(r3==r1)
{r3=r3+2;}
if(r3==r2)
{r3=r3+1;}
document.write("亂數r1:",+r1,"亂數r2:",+r2,"亂數r3:",+r3);
</Script>
</body>
</html>