[英]Drawing different colors of circles depending if a number exists in a variable or not
所以我得到了這個累積獎金編碼。 首先,它在1到36之間找到7個唯一的隨機數:
function RandomTal(Limit)
{
var RandomLottoTal
var Cont = true
while(Cont)
{
RandomLottoTal=Math.round(Math.random()*100+1)
if (RandomLottoTal <= Limit)
{
Cont = false
}
}
return RandomLottoTal;
}
function FindLottoTal()
{
var min = 1
var RandomTalNy
var LottoTal = []
for (var i=min; i<=7; i++)
{
RandomTalNy = RandomTal(36)
if(LottoTal.indexOf(RandomTalNy)<0)
{
LottoTal[i] = RandomTalNy
}
else
{
i--
}
}
DineLottoTal.value = LottoTal
return i;
}
然后,當我必須繪制圓時,某些操作無效。 我要執行的操作是檢查1-36中的所有數字,如果它與我的7個隨機大獎數字之一相同,則必須繪制一個紅色圓圈,否則必須繪制一個白色圓圈。 圓編碼:
function TegnCirkel()
{
var canvas = document.getElementById("LottoPlade")
var ctx = canvas.getContext("2d")
var LottoTalNy = FindLottoTal()
for (var j=1; j<=4; j++)
{
var Tæller = 0
for (var i=1; i<=9; i++)
{
Tæller = Tæller + 1
XPos = i*100-50
YPos = j*100-50
if (LottoTalNy.indexOf(Tæller)<0)
{
// Color for white not yet added
ctx.beginPath()
ctx.arc(XPos,YPos,20,0,2*Math.PI)
ctx.stroke()
}
else
{
// Color for red not yet added
ctx.beginPath()
ctx.arc(XPos,YPos,20,0,2*Math.PI)
ctx.stroke()
}
}
}
}
任何人都知道出了什么問題或解決方法。 非常感謝幫助:)
也許有幫助,但是我沒有太多時間去了解你想做什么
function TegnCirkel()
{
var canvas = document.getElementById("LottoPlade")
var ctx = canvas.getContext("2d")
var LottoTalNy = FindLottoTal()
for (var j=1; j<=4; j++)
{
var Tæller = 0
for (var i=1; i<=9; i++)
{
Tæller = Tæller + 1
XPos = i*100-50
YPos = j*100-50
if (LottoTalNy.toString().indexOf(Tæller)<0)
{
ctx.beginPath()
ctx.arc(XPos,YPos,20,0,2*Math.PI)
ctx.stroke()
}
else
{
ctx.beginPath()
ctx.arc(XPos,YPos,20,0,2*Math.PI)
ctx.stroke()
}
}
}
}
function RandomTal(Limit)
{
var RandomLottoTal
var Cont = true
while(Cont)
{
RandomLottoTal=Math.round(Math.random()*100+1)
if (RandomLottoTal <= Limit)
{
Cont = false
}
}
return RandomLottoTal;
}
function FindLottoTal()
{
var min = 1
var RandomTalNy
var LottoTal = []
for (var i=min; i<=7; i++)
{
RandomTalNy = RandomTal(36)
if(LottoTal.indexOf(RandomTalNy)<0)
{
LottoTal[i] = RandomTalNy
}
else
{
i--
}
}
FindLottoTal.value = LottoTal
return i;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.