2014-04-06 435 views
0

嘿傢伙,所以我需要幫助搞清楚我的JavaScript代碼中的錯誤是什麼。
調試生成圖像的javascript代碼

我確切知道代碼停止工作的位置,但我無法弄清楚問題所在。誰能幫忙?

function createCardio(){ 
var randomimages=new Array(); 

randomimages[0]="images/strength/armcircles.gif"; 
randomimages[1]="images/strength/calfraises.gif"; 
/**add more images**/ 

var preload=new Array() 

for (n=0;n<randomimages.length;n++){ 
    preload[n]=new Image() 
    preload[n].src=randomimages[n] 
} 

if(document.getElementById("impact").checked == false && document.getElementById("pregnant").checked == false && document.getElementById("none").checked == false){ 
document.getElementById("error").innerHTML = "*All fields are required"; 
} 
else if(document.getElementById("beginner").checked == false && document.getElementById("intermediate").checked == false && document.getElementById("advanced").checked == false){ 
    document.getElementById("error").innerHTML = "*All fields are required"; 
} 
else if(document.getElementById("hiit").checked == false && document.getELementById("tabata").checked == false && document.getElementById("circuit").checked == false){ 
    document.getElementById("error").innerHTML = "*All fields are required"; 
} 
else if(document.getElementById("treadmill").checked == false && document.getElementById("bike").checked == false && document.getElementById("jump").checked == false && document.getElementById("equipment").checked == false){ 
    document.getElementById("error").innerHTML = "*All fields are required"; 
} 
else{ 
if(document.getElementById("equipment").checked == true){ 
    if(document.getElementById("hiit").checked == true){   
     if(document.getElementById("impact").checked == true && document.getElementById("pregnant").checked == true){ 
      document.getElementById("input").innerHTML = "&nbsp;"; 
      document.getElementById("perform").innerHTML = "Perform each exercise for 40 seconds, followed by 20 seconds of rest (10 min)"; 

      document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>';  
     } 

     else if(document.getElementById("impact") == true){ 
      if(document.getElementById("beginner").checked == true){ 
       document.getElementById("input").innerHTML = "&nbsp;"; 
       document.getElementById("perform").innerHTML = "Perform each exercise for 40 seconds, followed by 20 seconds of rest (10 min)"; 

       document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
       document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
       document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
       document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
       document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
       document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
       document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
       document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[43]+'" width=40% height=40%>'; 
      } 
      else{ 
       document.getElementById("input").innerHTML = "&nbsp;"; 
       document.getElementById("perform").innerHTML = "Perform each exercise for 40 seconds, followed by 20 seconds of rest (10 min)"; 

       document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
      } 
     } 
     else if(document.getElementById("pregnant") == true){ 
      document.getElementById("input").innerHTML = "&nbsp;"; 
      document.getElementById("perform").innerHTML = "Perform each exercise for 40 seconds, followed by 20 seconds of rest (10 min)"; 

      document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(52-43)+43)]+'" width=40% height=40%>'; 
      document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(52-43)+43)]+'" width=40% height=40%>'; 
      document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(52-43)+43)]+'" width=40% height=40%>'; 
      document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
     } 
     else{ 
      document.getElementById("input").innerHTML = "&nbsp;"; 
      document.getElementById("perform").innerHTML = "Perform each exercise for 40 seconds, followed by 20 seconds of rest (10 min)"; 

      document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
     } 
    } 

這是代碼停止工作

else if(document.getElementById("tabata").checked == true){  
      if(document.getElementById("impact").checked == true && document.getElementById("pregnant").checked == true){ 
       document.getElementById("input").innerHTML = "&nbsp;"; 
       document.getElementById("perform").innerHTML = "Perform each exercise for 20 seconds, followed by 10 seconds of rest (10 min)Complete 3 rounds of 15-20 reps for each move"; 

       document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>';  

      } 
      else if(document.getElementById("impact") == true){ 
       if(document.getElementById("beginner").checked == true){ 
        document.getElementById("input").innerHTML = "&nbsp;"; 
        document.getElementById("perform").innerHTML = "Complete 3 rounds of 15-20 reps for each move"; 

        document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[43]+'" width=40% height=40%>'; 
       } 
       else{ 
        document.getElementById("input").innerHTML = "&nbsp;"; 
        document.getElementById("perform").innerHTML = "Complete 3 rounds of 15-20 reps for each move"; 

        document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       } 
      } 
      else if(document.getElementById("pregnant") == true){ 
       document.getElementById("input").innerHTML = "&nbsp;"; 
       document.getElementById("perform").innerHTML = "Complete 3 rounds of 15-20 reps for each move"; 

       document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(52-43)+43)]+'" width=40% height=40%>'; 
       document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(52-43)+43)]+'" width=40% height=40%>'; 
       document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(52-43)+43)]+'" width=40% height=40%>'; 
       document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      } 
      else{ 
       document.getElementById("input").innerHTML = "&nbsp;"; 
       document.getElementById("perform").innerHTML = "Complete 3 rounds of 15-20 reps for each move"; 

       document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      } 
     } 
     else{ 
      if(document.getElementById("impact").checked == true && document.getElementById("pregnant").checked == true){ 
       document.getElementById("input").innerHTML = "&nbsp;"; 
       document.getElementById("perform").innerHTML = "Complete 3 rounds of 15-20 reps for each move"; 

       document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>';  

      } 
      else if(document.getElementById("impact") == true){ 
       if(document.getElementById("beginner").checked == true){ 
        document.getElementById("input").innerHTML = "&nbsp;"; 
        document.getElementById("perform").innerHTML = "Complete 3 rounds of 15-20 reps for each move"; 

        document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*36)]+'" width=40% height=40%>'; 
        document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[43]+'" width=40% height=40%>'; 
       } 
       else{ 
        document.getElementById("input").innerHTML = "&nbsp;"; 
        document.getElementById("perform").innerHTML = "Complete 3 rounds of 15-20 reps for each move"; 

        document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
        document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*44)]+'" width=40% height=40%>'; 
       } 
      } 
      else if(document.getElementById("pregnant") == true){ 
       document.getElementById("input").innerHTML = "&nbsp;"; 
       document.getElementById("perform").innerHTML = "Complete 3 rounds of 15-20 reps for each move"; 

       document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(52-43)+43)]+'" width=40% height=40%>'; 
       document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(52-43)+43)]+'" width=40% height=40%>'; 
       document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
       document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(52-43)+43)]+'" width=40% height=40%>'; 
       document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*15)]+'" width=40% height=40%>'; 
      } 
      else{ 
       document.getElementById("input").innerHTML = "&nbsp;"; 
       document.getElementById("perform").innerHTML = "Complete 3 rounds of 15-20 reps for each move"; 

       document.getElementById("img1").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img2").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img3").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img4").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img5").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img7").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img8").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img9").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
       document.getElementById("img10").innerHTML = '<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*56)]+'" width=40% height=40%>'; 
      } 
     } 
    } 
} 
} 
+0

哪裏能忘記,我看到了嗎? –

+0

get_EL_ementById – hank

+0

_「停止工作」_它如何停止工作?你會得到錯誤嗎,代碼是否有點奇怪? –

回答

2

我需要幫助搞清楚我的javascript代碼的錯誤是什麼地方。

答案:在瀏覽器中使用「錯誤控制檯」來查看錯誤是什麼。在許多瀏覽器中,您可以按F12鍵進入。

2

這裏

else if(document.getElementById("impact") == true){ 

這裏

else if(document.getElementById("pregnant") == true){ 

你必須在其他報表.checked屬性。我假設這只是一個錯字? :)

可能還有其他錯誤。這正是我所看到的。 雖然你會對另一個人的建議感覺更好。

+0

當然是!感謝您的支持! – danih

1

H I,一些調試技巧 -

1)能速記這在很大程度上通過創建自己喜歡的功能 -

function _el(str) { return document.getElementById(str); }

,那麼你可以只使用el('img7').innerHTML="...砍伐所有這些document.getElementById聲明。

2)檢查是否checked === true是毫無意義的可以這樣做 -

if(document.getElementById("impact").checked) { ...

3)要調試,使用開發者工具在瀏覽器中使用/查看console這樣的:

console.log(document.getElementById("impact").checked)

使用console之前,你看到代碼打破會告訴你,如果你正在嘗試訪問的元素被發現,例如。

如果console.log(document.getElementById('perform')日誌,undefined你就會知道這些代碼將無法運行下一行 - document.getElementById('perform').innerHTML='...