0

I'm sorry, i'm very new to develop code. Now I'm doing some homework and want to do something outside of the textbook, but I'm failing ... :)

I created some simple html. Example:

  <tr>
    <td id="som1">5 + 3 =
      <input id="a_som1" type="number" required>
    </td>
    <td>
      <img src="goed.png" alt="goed" title="goed" id="i-s1g">
      <img src="fout.png" alt="fout" title="fout" id="i-s1f">
    </td>

And it ends with a button:

What I want is when you click on this button, the script checks your answer and either shows the "goed" or the "fout" image. I hided the images with a css-stylesheet and this code:

img {
  width: 35px;
  display: none;
}

I tried the following as javascript, however, it doesn't work. (I know this code is probably very stupid, I just tried some things when searching the internet.) I hope someone can help me :):

Oh, and is it necessary to use $(document).ready(function() { . It was in my textbook, but I don't really know if it's necessary...

$(document).ready(function() {
$("#cont").click {
  if ($("#a_som1").val() 8 ) {
      show("#i-s1g")
  }
  else {
      show("#i-s1f")
  }
  }

}

Thanks for helping!!

1 Answer 1

1

getting all the things i need 1:input 2:gIMAGE 3:fIMAGE & saving them in three variables..

putting eventListener on input of keypress then checking if the is enter,if is enter check if the number is equal to my answer("8").if yes show gimage and hide fimage,

if not hide gimage and show fimage

let input = document.getElementById("a_som1");
let gImg = document.getElementById("i-s1g");
let fImg = document.getElementById("i-s1f");

input.addEventListener("keypress", function(event) {
  if (event.key === "Enter") {

    if (input.value == 8) {
      gImg.style.display = "block"
      fImg.style.display = "none"
    } else {
      fImg.style.display = "block"
      gImg.style.display = "none"
    }
  }
});
img {
  width: 35px;
  display: none;
}
<tr>
  <td id="som1">5 + 3 =
    <input id="a_som1" type="number" required>
  </td>
  <td>
    <img src="goed.png" alt="goed" title="goed" id="i-s1g">
    <img src="fout.png" alt="fout" title="fout" id="i-s1f">
  </td>
</tr>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.