0

大幅に改訂されたプロジェクトの後(すべての入力に感謝します)、私はまだautorateLottery();をループできません。私のコンソールは私に言い続けます -

TypeError: document.getElementById(...) is null document.getElementById("random_0" + i).value = rnd;

私は自分のプロジェクトをhttp://jsfiddle.net/Ulleruller/2q2ne/17/に掲載しました

これが何を意味するのか、誰か教えてくれませんか?

私がそれを終わらせることができるよりも -

タンクス

 var match3 = 0, match4 = 0, match5 = 0, match6 = 0;
 var startLottery = false;
 var numberOfWeeks = 0;
 var numberOfMatches = 0;
 var totalWinnings = 0;
 var totalMatchedThisRound=0;
 var matchedNumbers = 0;

 var addUpMatches = function(matched){
matchedNumbers = matchedNumbers + matched;//---add up amount of matched numbers
totalMatchedThisRound = matchedNumbers; // ----store in new variable for 
};

var declareMatches = function(){//----declare matched numbers and keep totals 
switch(totalMatchedThisRound){
        case 3:
        console.log("Ching!! 3 matches");
        //console.log(amountOfThreeMatches);
        match3 = match3 + 1;
        totalWinnings = totalWinnings + 10;
        break;
        case 4:
        console.log("Ching!! 4 matches");
        match4 = match4 + 1;
        totalWinnings = totalWinnings + 70;
        break;
        case 5:
        console.log("Ching!! 5 matches");
        match5 = match5 + 1;
        totalWinnings = totalWinnings + 60000;
        break;
        case 6:
        console.log("Ching!! 6 matches");
        match6 = match6 + 1;
        totalWinnings = totalWinnings + 1000000;
        break;

        default:
        console.log("Alas only 2 or less matches");
        break;
           };

                   };

var clearCount = function(matched){ 
matchedNumbers = 0; //clears amount of matched numbers per round
};

var cleartempTotal = function(matched){ 
totalMatchedThisRound = 0; //clears amount of matched numbers per round
};

var start = function(){
startLottery = true;

};

var stop = function(){
startLottery = false;

};


function chooseNumbers() {//---chosen numbers check for doubles
    var checkForDouble ;
    var pickedNumbersArray= [];

    for(var t = 1; t < 7; t++){
        checkForDouble = parseInt(document.getElementById("picked_number_0" + t ).value);
                        document.getElementById("confirm_0" + t).value =  ("You have picked"+" " +document.getElementById("picked_number_0" + t ).value);
                        document.getElementById("confirm_0" + t).style.backgroundColor="green";

        for(var s = 0; s < 6; s++){
                if(checkForDouble == pickedNumbersArray[s]){
                    document.getElementById("confirm_0" + t).value =  ("Already chosen");
                    document.getElementById("confirm_0" + t).style.backgroundColor="red"
                }
        }
    pickedNumbersArray.push(checkForDouble);
    }
    };


var drawLotteryNumbers = function() { //generate numbers ensure unique
 var compareArray= []; 
 var rnd =0;

for(var i = 1; i < 7; i++){
            rnd = Math.floor((Math.random()*10)+1);
    while(rnd === compareArray[0]||rnd === compareArray[1]||rnd === compareArray[2]||rnd    === compareArray[3]||rnd === compareArray[4]||rnd === compareArray[5]){
                rnd = Math.floor((Math.random()*10)+1);
            };
            compareArray.push(rnd);
            document.getElementById("random_0" + i).value = rnd;
                    };
                };              

function automateLottery(){// generate - compare - stats
numberOfWeeks = numberOfWeeks + 1;//tally up rounds
drawLotteryNumbers();

var pickedNumber;
    for(var e = 1; e < 7; e++){
        document.getElementById("compare_0" + e).style.backgroundColor="white";
        document.getElementById("compare_0" + e).value=("No matches");
        pickedNumber = parseInt(document.getElementById("picked_number_0" + e).value);

        for(var i = 1; i < 7; i++){
            if(pickedNumber == document.getElementById("random_0" + i).value){
                document.getElementById("compare_0" + e).style.backgroundColor="green";
                document.getElementById("compare_0" + e).value=("You have matched number" + " "+ pickedNumber );
                addUpMatches(1); 
            }
        }
    }

    declareMatches();//----Add up per round and total
    document.getElementById("amountOfMatched").value = ("You have matched" + " " +totalMatchedThisRound + " "+ "numbers"); 
    document.getElementById("weeks").value = ("You have played for" + " " +numberOfWeeks + " "+ "weeks" );
    document.getElementById("moneyWon").value = ("You have won in total £"+ totalWinnings );
    document.getElementById("amountOfThreeMatches").value = ("You have so far had" + " " +match3 + " "+ "matches of three"  );
    document.getElementById("amountOffourMatches").value = ("You have so far had" + " " +match4 + " "+ "matches of four"  );
    document.getElementById("amountOffiveMatches").value = ("You have so far had" + " " +match5 + " "+ "matches of five"  );
    document.getElementById("amountOfsixMatches").value = ("You have so far had" + " " +match6 + " "+ "matches of six"  );

    clearCount();//clears amount matched every round
    cleartempTotal();//clears total matched every round
  };


 while(startLottery === true){
automateLottery();
  };
4

1 に答える 1

0

それはまさにそれがあなたに言っていることを意味します. ID「random_0」+ i を持つ要素はありません。この場合、「random_01」から「random_06」までになります。

于 2012-12-31T14:34:48.853 に答える