用户应输入五个数字,然后单击该按钮后,应随机提取另外五个数字。根据猜测的数字与随机数匹配的数量,程序应该打印六个不同的句子。 问题是我被卡住了,我不知道要解决它
<!doctype html>
<html lang=it>
<head>
<meta charset="utf-8">
<title>SUPERENALOTTO</title>
<script type="text/javascript">
function reset()
{
document.getElementById("numero1")"
document.getElementById("numero2")"
document.getElementById("numero3")"
document.getElementById("numero4")"
document.getElementById("numero5")"
}
function guessnumbers()
{
var num1,num2,num3,num4,num5,ran1,ran2,ran3,ran4,ran5,N,monete,listanum,ris1,ris2,ris3,ris4,ris5,tot,vincita;
num1=document.getElementById("num1").value;
num2=document.getElementById("num2").value;
num3=document.getElementById("num3").value;
num4=document.getElementById("num4").value;
num5=document.getElementById("num5").value;
monete=document.getElementById("monete").value;
ran1=Math.floor((Math.random()*50));
ran2=Math.floor((Math.random()*49));
ran3=Math.floor((Math.random()*48));
ran4=Math.floor((Math.random()*47));
ran5=Math.floor((Math.random()*46));
N=50;
listanum.apply(null, {length: N}).map(Number.call, Number)
if ((listanum[ran1]==num1)||(listanum[ran2]==num1)||(listanum[ran3]==num1)||(lista[ran4]==num1)||(lista[ran5]==num1))
{
ris1=1;
}
else ris1=0;
if ((listanum[ran1]==num2)||(listanum[ran2]==num2)||(listanum[ran3]==num2)||(lista[ran4]==num2)||(lista[ran5]==num2))
{
ris2=1;
}
else ris2=0;
if ((listanum[ran1]==num3)||(listanum[ran2]==num3)||(listanum[ran3]==num3)||(lista[ran4]==num3)||(lista[ran5]==num3))
{
ris3=1;
}
else ris3=0;
if ((listanum[ran1]==num4)||(listanum[ran2]==num4)||(listanum[ran3]==num4)||(lista[ran4]==num4)||(lista[ran5]==num4))
{
ris4=1;
}
else ris4=0;
if ((listanum[ran1]==num5)||(listanum[ran2]==num5)||(listanum[ran3]==num5)||(lista[ran4]==num5)||(lista[ran5]==num5))
{
ris5=1;
}
else ris5=0;
tot= ris1+ris2+ris3+ris4+ris5
if (tot==5)
{
vincita=(monete*20);
document.getElementById("result").innerHTML=" CINQUINA: Congratulazioni! Vinci "+vincita;
}
if (tot==4)
{
vincita=(monete*10);
document.getElementById("result").innerHTML=" Quaterna: Congratulazioni! Vinci "+vincita;
}
if (tot==3)
{
vincita=(monete*5);
document.getElementById("result").innerHTML=" Terna: Congratulazioni! Vinci "+vincita;
}
if (tot==2)
{
vincita=(monete*2);
document.getElementById("result").innerHTML=" Ambo: Vinci "+vincita;
}
if (tot==1)
{
vincita=(monete*1);
document.getElementById("result").innerHTML=" Un solo numero indovinato: Non perdi e non guadagni ";
}
if (tot==0)
{
vincita=(monete*0);
document.getElementById("result").innerHTML=" Mi dispiace: perdi tutto";
}
}
</script>
</head>
<body>
<div id="titolo">
<h1 id="myDIV">superenalotto</h1>
</div>
<div id="informazione">
</div>
<div id="gioco">
<form>
<p style="text-align:center; font-size:30px ">
<br>
1°Numero <input type="text" id="num1" name="num1">
<br><br>
2°Numero <input type="text" id="num2" name="num2">
<br><br>
3°Numero <input type="text" id="num3" name="num3">
<br><br>
4°Numero <input type="text" id="num4" name="num4">
<br><br>
5°Numero <input type="text" id="num5" name="num5">
<br><br>
Numero pescato1 <input type="text" id="num6" name="num6">
<br><br>
Numero pescato2 <input type="text" id="num7" name="num7">
<br><br>
Numero pescato3 <input type="text" id="num8" name="num8">
<br><br>
Numero pescato4 <input type="text" id="num9" name="num9">
<br><br>
Numero pescato5 <input type="text" id="num10" name="num10">
<br><br>
<h2 style="font-size: 30px; "> Inserisci la tua scommessa</h2>
<br>
<input type="text" id="monete" name="monete">
<br><br>
<input type="button" id="submit" name="Gioca" value="Gioca" onclick="guessnumbers()">
<br><br>
<span id="result" style="font-size:25px; color:red"> </span>
<br>
<br>
<br><br><br>
<input type="submit" id="submit" name="cancella" style=" background- color:red; width:160px; height:50px" value="Ritenta" onclick="reset()">
</form>
</div>
<br><br><br><br><br>
</body>
</html>
答案 0 :(得分:0)
var howManyNumbers = 5;
var rememberNumbersArray = []; // We do not repeat numbers
createInput("userInputId", false, "Type number from 1 to 10");
createInput("inputId", true);
// create 6 (howManyNumbers) inputs
function createInput(name, disabled, placeholder){
for(var e = 0; e<howManyNumbers; e++){
lottery.innerHTML+=e+". ";
var input = document.createElement("input");
input.type = "text";
input.id = name+e; // id
if(placeholder){
input.placeholder = placeholder;
}
input.disabled = disabled;
lottery.appendChild(input); // put it into the DOM
lottery.innerHTML+="<BR><BR>"; // gap :D you can use
}
}
function randomNumbers(){
// clear rememberNumbersArray for next lottery :D
rememberNumbersArray = [];
// clear results
results.innerHTML = "";
var count = howManyNumbers;
var numberRnd = 0;
var rndNmb = 0;
var count = 0;
while(count<howManyNumbers){
// ...random
rndNmb = mt_rand(10,1);
if(rememberNumbersArray.indexOf(rndNmb)==-1){
// update input
document.getElementById("inputId"+count).value = rndNmb;
// Remember a random number
rememberNumbersArray.push(rndNmb);
// if count == howManyNumbers, break the loop
count++;
}
}
// check if somebody win
checkWin(count);
}
function checkWin(id){
results.innerHTML = "Winning numbers: <BR>";
for(var e = 0; e<rememberNumbersArray.length; e++){
for(var a = 0; a<howManyNumbers; a++){
if(rememberNumbersArray[e]==document.getElementById("userInputId"+a).value){
results.innerHTML += rememberNumbersArray[e]+"<BR>";
}
}
}
}
function mt_rand(max, min){
return Math.floor(Math.random() * max) + min;
}
Welcome to ITALIA SUPER LOTTO 2017<BR><BR>
<div id="lottery"></div>
<button onclick="randomNumbers();">Generate</button>
<div id="results"></div>