View Single Post
Old 12-06-2017, 03:50 PM   #9
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,738
Karma: 24031403
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Sdumau1 View Post
is it possible, give an id to each answer, where one ID for all wrong answers and another id to all "Correct" and use a switch to never appear the image wrong twice?
No, all ids in an HTML file need to be unique, however, you could mark right and wrong answers with different class names.

Code:
<p><img alt="" class="wrong" onclick="checkAnswer(this)" src="../Images/help.png"/>Answer 3</p>

<p><img alt="" class="correct" onclick="checkAnswer(this)" src="../Images/help.png"/>Answer 4</p>
You could then have an onclick function check the class name and display the desired image. For example:

Code:
function checkAnswer(img) {
    if (img.classList.contains("correct")) {
        img.src = "../Images/ok-filled.png";
    } else { 
        img.src = "../Images/cancel-filled.png";
    }
}
I've attached an updated test file that demonstrates this method.

Before you continue, you really should work through a JavaScript tutorial for beginners, for example, the JavaScript Tutorial by w3schools.
Also don't forget to periodically check your epub with the IDPF EPUB validator.
Attached Files
File Type: epub quiz_script_2_epub3.epub (9.3 KB, 204 views)
Doitsu is offline   Reply With Quote