javascript - Defined variable results in null -


i've been trying code something, isn't working:

<html> <head> <style>  .borderaroundnumber{ border-style: inset; margin-left: 40%; margin-right: 40%; text-align: center;}      </style> </head> <body>  <h1>testing thing</h1>  <button onclick="whatistheword()">click here</button> <button onclick="checktranslations()">check</button> </br> </br> <div class="borderaroundnumber"> <p1 id="aos" class="numberofsentencesstyle"></p1> </div>  </br> <p1 id="word1"></p1> <p1 id="spacing1"></p1> <p1 id="answer1"></p1> <p1 id="iscorrectornot1"></p1> </br> <p1 id="word2"></p1> <p1 id="spacing2"></p1> <p1 id="answer2"></p1> <p1 id="iscorrectornot2"></p1> </br> <p1 id="word3"></p1> <p1 id="spacing3"></p1> <p1 id="answer3"></p1> <p1 id="iscorrectornot3"></p1> </br> <p1 id="word4"></p1> <p1 id="spacing4"></p1> <p1 id="answer4"></p1> <p1 id="iscorrectornot4"></p1> </br> <p1 id="word5"></p1> <p1 id="spacing5"></p1> <p1 id="answer5"></p1> <p1 id="iscorrectornot5"></p1> </br> <p1 id="word6"></p1> <p1 id="spacing6"></p1> <p1 id="answer6"></p1> <p1 id="iscorrectornot6"></p1> </br> <p1 id="word7"></p1> <p1 id="spacing7"></p1> <p1 id="answer7"></p1> <p1 id="iscorrectornot7"></p1>  <script>  var counter1 = 0; var counter2 = 0; var iscorrect =0; var amountofsentences = prompt("what amount of sentences?");  function whatistheword(){  document.getelementbyid("aos").innerhtml = amountofsentences;  while(counter1 < amountofsentences){      var counter1plus1 = counter1 + 1;     var word = prompt("what word "+ counter1plus1);     document.getelementbyid("word" + counter1plus1).innerhtml = word;     document.getelementbyid("spacing" + counter1plus1).innerhtml = "   =   ";     var translation = prompt("what translation of " + word);     document.getelementbyid("translation" + counter1plus1).innerhtml = translation;              <---     counter1++;  } }  function checktranslations(){  while(counter2 < amountofsentences){      var counter2plus1 = counter2 + 1;     var answer = prompt("what translation of " + document.getelementbyid("word" + counter2plus1).innerhtml);     document.getelementbyid("answer" + counter2plus1).innerhtml = answer;      if(document.getelementbyid("answer" + counter2plus1).innerhtml == document.getelementbyid("translation" + counter2plus1)){          document.getelementbyid("iscorrectornot" + counter2plus1).innerhtml = "is correct";      }     else{         document.getelementbyid("iscorrectornot" + counter2plus1).innerhtml = "is wrong";     }     counter2++; } }  </script>  </body> </html> 

i'm sorry clustertruck, i'm quite new html , javascript. "translation" variable keeps outputting null though defined line before.

    var translation = prompt("what translation of " + word);     document.getelementbyid("translation" + counter1plus1).innerhtml = translation; 

the "translation" variable keeps outputting null though defined line before.

its not translation variable null, call document.getelementbyid("translation" + counter1plus1) returns null.

there no elements on page follow pattern translation1...translation2....translation[n].

perhaps meant fill answer[n] elements

var translation = prompt("what translation of " + word); document.getelementbyid("answer" + counter1plus1).innerhtml = translation; 

as aside question, have simple html error - </br> should <br>.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -