我已经创建了简单的乐透模拟器,我想将其设置为仅在特定条件下显示数字。假设要显示至少两个或两个以上的数字(选择并滚动),我是初学者,因此对任何明显的错误表示歉意,我仍在学习。
var attempt = 0;
function losowanie1() {
var available = 6;
var guessed = new Array();
r = new Array(available);
var xd0 = document.getElementById("pole1").value
var xd1 = document.getElementById("pole2").value
var xd2 = document.getElementById("pole3").value
var xd3 = document.getElementById("pole4").value
var xd4 = document.getElementById("pole5").value
var xd5 = document.getElementById("pole6").value
y = new Array(6)
y[0] = xd0
y[1] = xd1
y[2] = xd2
y[3] = xd3
y[4] = xd4
y[5] = xd5
z = new Array(6)
for (var i = 0; i <= available - 1; i++) {
r[i] = Math.floor((Math.random() * (49 - 1)) + 1);
if ((y[i] == r[0]) || (y[i] == r[1]) || (y[i] == r[2]) || (y[i] == r[3]) || (y[i] == r[4]) || (y[i] == r[5])) {
guessed.push(y[i]);
}
}
atempt++
document.getElementById("wysw").innerHTML = r;
document.getElementById("zatw").innerHTML = guessed;
document.getElementById("zatw2").innerHTML = attempt;
}
#wysw {
color: yellow;
background-color: black;
height: 200px;
text-align: center;
font-size: 40px;
}
}
#zatw {
margin-top: 40px;
height: 200px;
background-color: pink;
text-align: center;
}
#dupa {
height: 200px;
background-color: brown;
text-align: center
}
#tak {
width: 200px;
height: 100px;
text-align: center;
margin-left: 850px;
}
#zatw2 {
margin-top: 40px;
height: 200px;
background-color: orange;
text-align: center;
}
<main>
<div id="main">
<h1>Totolotek</h1>
<div id="blokada">
<br>
<div id="wysw"></div>
<div id="dupa">
<input type="text" id="pole1" /><input type="text" id="pole2" /><input type="text" id="pole3" /><input type="text" id="pole4" /><input type="text" id="pole5" /><input type="text" id="pole6" />
<input type="reset" id="tak" value="zatwierdz" onclick="losowanie1();" />
<div id="zatw"></div>
<div id="zatw2"></div>
</div>
</div>
</div>
</main>
答案 0 :(得分:0)
Here's a JSFiddle-我只是在猜你在做什么。
您有错字:atempt++
。
在修复该问题后似乎可以正常工作。
var attempt = 0;
function losowanie1() {
var available = 6;
var guessed = new Array();
r = new Array(available);
var xd0 = document.getElementById("pole1").value
var xd1 = document.getElementById("pole2").value
var xd2 = document.getElementById("pole3").value
var xd3 = document.getElementById("pole4").value
var xd4 = document.getElementById("pole5").value
var xd5 = document.getElementById("pole6").value
y = new Array(6)
y[0] = xd0
y[1] = xd1
y[2] = xd2
y[3] = xd3
y[4] = xd4
y[5] = xd5
z = new Array(6)
for (var i = 0; i <= available - 1; i++) {
r[i] = Math.floor((Math.random() * (49 - 1)) + 1);
if ((y[i] == r[0]) || (y[i] == r[1]) || (y[i] == r[2]) || (y[i] == r[3]) || (y[i] == r[4]) || (y[i] == r[5])) {
guessed.push(y[i]);
}
}
attempt++
document.getElementById("wysw").innerHTML = r;
document.getElementById("zatw").innerHTML = guessed;
document.getElementById("zatw2").innerHTML = attempt;
}