Compare and Count Character help
My problem is my innerHTML is still displaying 0 matches, even when put the answer in. Is there something can I do differently? Any help would appreciated.
Here is the code:
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Midterm game</title> <script language="javascript"> var word = "album"; var tries = 0; var count = 0; function guessing(word) { tries++; guess = document.getElementById("txt1").value = ""; for(i = 0; i<guess.length; i++) { if(guess[i] === word) { alert("Congradulations! You got it!"); count++; break; } } document.getElementById("result").innerHTML = "You have " + count + " matches"; if(tries > 5) { alert("Sorry, game over!"); } } function cc() { var letter = guess.charAt(0) } </script> </head> <body> <h1>Jotto</h1> <b><p>Guess the five letter word! You get 5 tries.</p></b> <form> <p><input type="text" id="txt1" /></p> <p><input type="button" id="btn1" value="Guess" onclick="guessing()" /></p> <p><div id="result"></div></p> </form> </body> </html>
-
Marketing Profits Software -
Thanks
{{ DiscussionBoard.errors[2290520].message }} -