Почему при проверке файла console.log не добавляются мои оценки var?

Почему моя оценка var не соответствует добавлению при проверке console.log?

 {amp}lt;html{amp}gt; {amp}lt;head{amp}gt; {amp}lt;style{amp}gt; #hidden1{ display: none; } {amp}lt;/style{amp}gt; {amp}lt;/head{amp}gt; 
 {amp}lt;script{amp}gt; var ques = ["THIS IS QUESTION 0","THIS IS QUESTION 1","THIS IS QUESTION 2","THIS IS QUESTION 3","THIS IS QUESTION 4","THIS IS QUESTION 5","THIS IS QUESTION 6","THIS IS QUESTION 7","THIS IS QUESTION 8","THIS IS QUESTION 9"]; var randnum = rand(); var ch0; var minus = 10; var op1; var op2; var op3; var correctans11; var correctans21; var correctans31; var correctans12; var correctans22; var correctans32; var correctans13; var correctans23; var correctans33; var correctans14; var correctans24; var correctans34; var correctans15; var correctans25; var correctans35; var correctans16; var correctans26; var correctans36; var correctans17; var correctans27; var correctans37; var correctans18; var correctans28; var correctans38; var correctans19; var correctans29; var correctans39; var correctans10; var correctans20; var correctans30; function startquiz(){ quiz(); document.getElementById('hidden1').style.display='block'; document.getElementById('hidden2').style.display='none'; } function quiz(){ randnum = rand(); funquiz(); } function rand(){ var x= Math.floor(Math.random() * minus); return x; } function funquiz(){ /*if(ques[randnum] === undefined){ quiz(); } if(ques[randnum]){ document.getElementById('question').innerHTML=ques[randnum]; delete ques[randnum]; choices(); }*/ if(minus {amp}gt;=0 ){ document.getElementById('question').innerHTML=ques[randnum]; choices(); } } function choices(){ if(randnum == 0){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans01","correctans02","ans03"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans11 = document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans21 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans31 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } if(randnum == 1){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans11","correctans12","ans13"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans12 = document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans22 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans32 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } if(randnum == 2){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans21","correctans22","ans23"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans13 = document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans23 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans33 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } if(randnum == 3){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans31","correctans32","ans33"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans14 = document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans24 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans34 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } if(randnum == 4){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans41","correctans42","ans43"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans15 = document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans25 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans35 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } if(randnum == 5){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans51","correctans52","ans53"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans16 = document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans26 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans36 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } if(randnum == 6){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans61","correctans62","ans63"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans17 = document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans27 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans37 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } if(randnum == 7){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans71","correctans72","ans73"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans18 = document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans28 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans38 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } if(randnum == 8){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans81","correctans82","ans83"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans19= document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans29 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans9 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } if(randnum == 9){ var numchoice = 3; var numdeduct = Math.floor(Math.random() * numchoice); var ch0 = ["ans91","correctans92","ans93"]; document.getElementById('choice1').innerHTML=ch0[numdeduct]; op1 = ch0[numdeduct]; correctans10 = document.getElementById('choiceset1').value = op1; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice2').innerHTML=ch0[numdeduct]; op2 = ch0[numdeduct]; correctans20 = document.getElementById('choiceset2').value = op2; ch0.splice(numdeduct,1); numchoice--; numdeduct = Math.floor(Math.random() * numchoice); document.getElementById('choice3').innerHTML=ch0[numdeduct]; op3 = ch0[numdeduct]; correctans30 = document.getElementById('choiceset3').value = op3; ch0.splice(numdeduct,1); numchoice--; } } var score = 0; function pass(){ var check1 = document.getElementById('choiceset1').checked; var check2 = document.getElementById('choiceset2').checked; var check3 = document.getElementById('choiceset3').checked; if(randnum == 0){ if(check1 === true){ if(correctans11 == 'correctans02'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans21 == 'correctans02'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans31 == 'correctans02'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } if(randnum == 1){ if(check1 === true){ if(correctans12 == 'correctans12'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans22 == 'correctans12'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans32 == 'correctans12'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } if(randnum == 2){ if(check1 === true){ if(correctans13 == 'correctans22'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans23 == 'correctans22'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans33 == 'correctans22'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } if(randnum == 3){ if(check1 === true){ if(correctans14 == 'correctans32'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans24 == 'correctans32'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans34 == 'correctans32'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } if(randnum == 4){ if(check1 === true){ if(correctans15 == 'correctans42'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans25 == 'correctans42'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans35 == 'correctans42'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } if(randnum == 5){ if(check1 === true){ if(correctans16 == 'correctans52'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans26 == 'correctans52'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans36 == 'correctans52'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } if(randnum == 6){ if(check1 === true){ if(correctans17 == 'correctans62'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans27 == 'correctans62'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans37 == 'correctans62'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } if(randnum == 7){ if(check1 === true){ if(correctans18 == 'correctans72'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans28 == 'correctans72'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans38 == 'correctans72'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } if(randnum == 8){ if(check1 === true){ if(correctans19 == 'correctans82'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans29 == 'correctans82'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans39 == 'correctans82'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } if(randnum == 9){ if(check1 === true){ if(correctans10 == 'correctans92'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check2 === true){ if(correctans20 == 'correctans92'){enter code here score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } if(check3 === true){ if(correctans30 == 'correctans92'){ score  ; console.log(score); ques.splice(randnum,1); minus--; quiz(); } } } } {amp}lt;/script{amp}gt; {amp}lt;div id="hidden2"{amp}gt; {amp}lt;button onclick="startquiz()"{amp}gt;start{amp}lt;/button{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div id="hidden1"{amp}gt; {amp}lt;p id="question"{amp}gt;{amp}lt;/p{amp}gt; {amp}lt;form{amp}gt; {amp}lt;input type="radio" id="choiceset1" name="choiceset"{amp}gt;{amp}lt;b id="choice1"{amp}gt;{amp}lt;/b{amp}gt;{amp}lt;br{amp}gt; {amp}lt;input type="radio" id="choiceset2" name="choiceset"{amp}gt;{amp}lt;b id="choice2"{amp}gt;{amp}lt;/b{amp}gt;{amp}lt;br{amp}gt; {amp}lt;input type="radio" id="choiceset3" name="choiceset"{amp}gt;{amp}lt;b id="choice3"{amp}gt;{amp}lt;/b{amp}gt;{amp}lt;br{amp}gt; {amp}lt;/form{amp}gt; {amp}lt;button onclick="pass()"{amp}gt;NEXT{amp}lt;/button{amp}gt; {amp}lt;/div{amp}gt; 

Я пытаюсь сделать викторину, используя JS в качестве моего проекта для начинающих. Вопросы должны быть случайными и не должны повторяться. Моя проблема в том, что моя переменная скоринга не всегда согласована, и это можно увидеть в console.log. Я даже установил ненужные переменные, чтобы увидеть, будет ли это иметь значение, но не повезло. Что я делаю неправильно?

Понравилась статья? Поделиться с друзьями:
JavaScript & TypeScript
Adblock
detector