Right, I am trying to make this game for javascript and to customize it, I have the game working which is the basic guess your number game what im trying to do is figure out how to get my output to be an image rather then be text. Here is my code.
<script type="text/javascript">
function yourGuess() {
guess = document.getElementById("guess").value;
guesses = document.getElementById("output");
if (guess == numToGuess) {
guesses.value = guesses.value + "\r" + "You have guessed correctly! ("+guess+")";
} else if (guess > numToGuess) {
guesses.value = guesses.value + "\r" + "Your guessing too high!("+guess+")";
} else {
guesses.value = guesses.value + "\r" + "Your guessing too low!("+guess+")";
}
}
var numToGuess = Math.floor(Math.random()*100);
</script>
<fieldset style="float: left; width: 380px; background-color:pink;">
<legend >Inputs</legend>
<label for="guess">Your Guess:</label>
<input type="text" id="guess" value="Between 1-100" />
<input type="button" onclick="yourGuess()" value="submit" /><br />
<input type="button" onclick="" value="Show My Guesses" />
<input type="button" onclick="" value="New Game" /><br />
</fieldset>
<fieldset style="float: left; width: 380px; background-color:red;">
<legend style="background-color:Lime; color:Blue;"> Output </legend>
<textarea id="output" name="output" rows="5" style="width: 100%;"></textarea>
</fieldset>
Here is a Jsfiddle link: http://jsfiddle.net/92PCR/2/
Can anyone help?
It's as simple as adding an image element:
<img id="outputimg" src="//:0" alt="output" />
and then alter the source of that image like this:
document.getElementById("outputimg").src = "yourNumber.gif";
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments