Adding images to Javascript Code

Saint

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?

Ke Vin

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Adding a line in javascript code

From Dev

Adding a line in javascript code

From Dev

Adding html file, css file , few javascript files and a few images to django code?

From Dev

Wordpress - Adding template folder images to javascript

From Dev

Adding javascript code in iframe.

From Dev

Java Swing adding images code in MigLayout does not seem to be working?

From Dev

Debugging JavaScript & css code: adding an event handler

From Dev

Simplifying Jquery/Javascript code and adding animation

From Dev

Adding a class to all the images within a <div> using javascript & vice versa

From Dev

Adding a class to all the images in the webpage except for a particular <div> using javascript

From Dev

Adding a class to all the images within a <div> using javascript & vice versa

From Dev

Javascript - Adding images to objects via object literal notation

From Dev

Javascript add link to images which are switched by code

From Dev

Inserting images through javascript code to the database

From Dev

What is wrong with this code? Switching images with pure javascript

From Dev

Rails adding images to a Post

From Dev

Adding two images PHP

From Dev

Adding Images iOS xCode

From Dev

Adding images with Angular JS

From Dev

Adding images to the end of the video

From Dev

jsPDF with Cordova - Adding images

From Dev

Adding a Preloader to an Bunch of Images

From Dev

Adding space between images?

From Dev

Adding images to the end of the video

From Dev

Adding a Preloader to an Bunch of Images

From Dev

Adding images to buttons in listview

From Dev

Adding two images PHP

From Dev

Adding multiple images with paperclip

From Dev

Adding space between images?

Related Related

HotTag

Archive