0

I am making a multiple choice quiz, but my program won't work. I am storing the score of each question in variable, which in this case is a. I am trying to have one function determine all the scores, but for some reason it decides that num2 which is supposed to represent a, is being created as its own variable. Please help.

All the images are stored locally so they won't show up, but the function works in telling what is right or wrong, the variable just doesn't store.

<!DOCTYPE html>
<html>
<body>

<h1>What Information did you retain?</h1>

<p id="Grade"></p>
  <br>
<p>#1 Do I have a pet? </p>

<button type="button" onclick="button(1, a)">A. None</button><br>
<button type="button" onclick="button(0, a)">B. Yes a Dog</button>
<br>
<img id="myImage" src="which.jfif" style = float:right;width="200" height="180">
<br>

 <script>
var a = 0;
var b = 0;
var c = 0;
var d = 0;
var e = 0;
var Awnser;
function button(num, num2) {
    if (num == 1) {
        if (num2 == 0) {
            num2++
            Awnser = "correct.jfif"
            console.log(a);
        }
    } else {
        Awnser = "wrong.jfif"
    }
    document.getElementById('myImage').src = Awnser;
}

</script>
</body>
</html> 

1 Answers1

0

Your JS is correct.

The issue in the style that you are setting..

<img id="myImage" src="which.jfif" style = float:right;width="200" height="180">

Change it to:

<img id="myImage" src="which.jfif" style = "float:right;width:200px;height:180px">

The style needs to have value in quotes and you are missing that.

John
  • 3,716
  • 2
  • 19
  • 21
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78