Hi, so I'm creating a hangman game with only basic skills in java&html. I'm having a great trouble as to how to make it work. What I'm trying to do is very simple: When I type a word, a box will pop up and say, "----" (if it's 4 words) or "-----"(if it's 5 ) words) And Then if the word matches with what I typed, it will show "--d-" or something like that.
It obviously doesn't have advanced skills, and I can't use them at my level. So please correct where it's wrong.. Thanks.
<!Doctype html>
<html>
<head>
<h1> H A N G M A N </h1>
<img src="HangmanStep1.gif" id="hangman"> </img>
<script>
var secretword
var secretword=["horse","frogs","turtle","snail","chicken","turkey","bird","dorphin","lion","bear",
"cat","dog","spider"]
var click=0
var WrongGuess=""
var RightGuess=""
var numwrong=0
var numright=0
var guess=""
var n=0
function haha() {
guess=document.getElementById("type").value
n=secretword.search(guess)
if (n==-1){alert("Wrong!")
numwrong=numwrong+1
WrongGuess=WrongGuess+guess
document.getElementById("text1").innerHTML=(WrongGuess)
}
else {alert("That Guess Is right and is in the " + (n+1) + "space" )
numright=numright+1
RightGuess=RightGuess+guess
document.getElementById("text2").innerHTML=(RightGuess)
}
alert("Your Guess is" + " " +(click++) + " " + "Times")
if (numwrong==1) {document.getElementById("hangman").src="HangmanStep2.gif"}
if (numwrong==2) {document.getElementById("hangman").src="HangmanStep3.gif"}
if (numwrong==3) {document.getElementById("hangman").src="HangmanStep4.gif"}
if (numwrong==4) {document.getElementById("hangman").src="HangmanStep5.gif"}
if (numwrong==5) {document.getElementById("hangman").src="HangmanStep6.gif"}
if (numwrong==6) {document.getElementById("hangman").src="HangmanStep7.gif"}
}
function ChangeWords() {
answer="----"
n=secretword.search("r")
alert(answer)
answer=answer.substring(0,n) + "r" + answer.substring(n,answer.length)
alert(answer)
}
</script>
</head>
<body>
<input type="text" id="type" />
<input type="button" value="Submit" onClick="haha()" onClick="ChangeWords()"/>
<br> <br>
Wrong Letters <p id="text1"> ----- </p>
Right Letters <p id="text2"> ----- </p>
</body>
</html>