Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling JavaScript function in Html
    text
    copied!<p>I am new to Javascript and I would really appreciate your help . I am coding Hangman using JavaScript, Html, Css. I was able to genrate random Word ans also create placeholders based on the length. But when i am clicking on letter, i want to run the function which will check if word contains the letter, if yes it will place that letter in corresponding placeholder. This is how i am generating available letters. I am unable to run check function upon clicking</p> <p>Here is the link to <a href="http://jsfiddle.net/maddysin/9Hhuy/" rel="nofollow"><strong>jsfiddle</strong></a>, Please advice! </p> <pre><code>document.write('&lt;div class="letters"&gt;'); document.write('&lt;table&gt;'); document.write('&lt;tr&gt;'); document.write('&lt;td&gt;'); var alpha= new alphabetArray(); function alphabetArray() { this[0] = "A"; this[1] = "B"; this[2] = "C"; this[3] = "D"; this[4] = "E"; this[5] = "F"; this[6] = "G"; this[7] = "H"; this[8] = "I"; this[9] = "J"; this[10] = "K"; this[11] = "L"; this[12] = "M"; this[13] = "N"; this[14] = "O"; this[15] = "P"; this[16] = "Q"; this[17] = "R"; this[18] = "S"; this[19] = "T"; this[20] = "U"; this[21] = "V"; this[22] = "W"; this[23] = "X"; this[24] = "Y"; this[25] = "Z"; } var err=0; for (i=0; i&lt;26; i++) //document.write('&lt;a href="#" onClick="check('+alpha[i]+')";/&gt;'+alpha[i]+ " " +'&lt;/a&gt;'); //document.write('&lt;input type="submit" ;onClick=check('+this.alpha[i]+'); value='+alpha[i]+'&gt;'); document.write('&lt;input type=\"submit\" onClick=\"javascript:check('+alpha[i]+')\" value='+alpha[i]+'&gt;'); document.write('&lt;/td&gt;'); document.write('&lt;/tr&gt;'); var words=['acres','adult','brick','calm','canal','claws','coach','constantly','contrast','cookies','customs']; function chooseWords(){ var ranWord=words[Math.floor(Math.random() * words.length)]; return ranWord; } function fillBlanks(word){ var res=" "; for(j=0;j&lt;word.length;j++){ res= "_ " + res; } return res; } document.write('&lt;tr&gt;'); document.write('&lt;td&gt;'); var answer=chooseWords(); document.write(answer); var output=fillBlanks(answer); var res1=output.split(" "); document.write('&lt;div id=1&gt;&lt;font size=15 &gt;&lt;b&gt;'+output +'&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;'); document.write('&lt;/td&gt;'); document.write('&lt;/tr&gt;'); document.write('&lt;/table&gt;'); document.write('&lt;/div&gt;'); document.write('&lt;div class="hangArea"&gt;'); document.write('&lt;div class="top"&gt;'); document.write('&lt;/div&gt;'); document.write('&lt;div class="left"&gt;');document.write('&lt;/div&gt;'); document.write('&lt;div class="base"&gt;');document.write('&lt;/div&gt;'); document.write('&lt;/div&gt;'); document.write('&lt;div class="drawarea"&gt;'); document.write('&lt;div class="rope"&gt;');document.write('&lt;/div&gt;'); document.write('&lt;div class="head"&gt;');document.write('&lt;/div&gt;'); document.write('&lt;div class="body&gt;');document.write('&lt;/div&gt;'); document.write('&lt;div class="leftarm"&gt;');document.write('&lt;/div&gt;'); document.write('&lt;div class="rightarm"&gt;');document.write('&lt;/div&gt;'); document.write('&lt;div class="leftleg"&gt;');document.write('&lt;/div&gt;'); document.write('&lt;div class="rightleg&gt;');document.write('&lt;/div&gt;'); document.write('&lt;/div&gt;'); f function check(alpha){ for(i=0;i&lt;answer.length;i++){ document.write(alpha); if(answer.charAt(i)===alpha.toLowerCase()){ res1[i]=alpha; document.write(res1[i]); document.getElementById('1').innerHTML=res1[i]; } } } </code></pre> <p>Please guide!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload