Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to add an image, which follows a specific question, because I am doing a quiz.

It sould be in the variable, but want I have found is I should just write the file in, like this: "raev.png". But the image doesn't appear.


I am not good at English, so I haven't been able to understand the things I read, when I google my problem.

What I have tried:

HTML code
<p id="message">
      Skriv navnet på dette dyr: <br><img src="" id="name">
    </p>
    <div id="disappear">
      <input type="text" id="input" />
      <button onclick="submit()" id="knap">Tjek</button>
    </div>
    <p id="answer"></p>
    <p id="button"></p>


Javascript
var forkortelser = [
        "raev.png",];
      var ord = [
        "ræv",
        ];
      var random = Math.floor(Math.random() * forkortelser.length);

      function submit() {
        var b = input.value;
        if (random == 0 && b == ord[0]) {
          document.getElementById("answer").innerHTML = "Rigtigt!";
          document.getElementById("button").innerHTML =
            "<button onclick=btn001() id=knap>Næste</button>";
          document.getElementById("disappear").innerHTML = "";
        }

<pre>document.getElementById("name").innerHTML = forkortelser[random];

      function btn001() {
        random = Math.floor(Math.random() * forkortelser.length);
        document.getElementById("name").innerHTML = forkortelser[random];
        document.getElementById("button").innerHTML = "";
        document.getElementById("disappear").innerHTML =
          "<input type=text id=input /><button onclick=submit() id=knap>Tjek</button>";
        document.getElementById("answer").innerHTML = "";
      }
Posted
Updated 29-Jul-20 6:50am
v2

1 solution

You need to use the HTML <img> tag, as described at HTML img tag[^].
 
Share this answer
 
Comments
Marie Jensen 28-Jul-20 12:30pm    
Like this?
var image = ["img src="raev.png""];

Because this doesn't work
Richard MacCutchan 28-Jul-20 12:37pm    
No, because that does not mean anything. Please use the Improve question link above, and show the code that you are using, and explain what happens.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900