Basically I am trying to find the most efficient way to simply add an image to each question. The text works fine if I just use that. But the images don't display and I am new to Javascript. Any help would be appreciated.
I have declared an array as follows: it should have an image for the question, an array of answers for the choices, and an answer.
var questions=[
new Question("http://path/hombre.jpg",["man","day","weather","time"],"man"),
new Question("http://path/day.jpg", ["year","thing","part/portion","day"],"year"),];
Here is the function that populates the questions in the app. There is more code in js and html of course however I would like to know if there is a command or shortcut i can use to display the image along with the other text as part of a question. Here is the code for the function that works fine if it is text only:
function populate(){
if(quiz.isEnded()){
showScores();
}
else{
//show question and try to put the picture here
var element = document.getElementById("question");
element.innerHTML = quiz.getQuestionIndex().text;
//Show Choices
var choices = quiz.getQuestionIndex().choices;
for (var i=0; i< choices.length; i++){
var element = document.getElementById("choice" + i);
element.innerHTML = choices[i];
guess("btn"+ i, choices[i]);
}
showProgress();
}
};
};
try this:
element.innerHTML = ('<img src='+choices[linkPosition]+'>');
element.innerHTML += choices[restOfContentLocation];
Or however/wherever you store the image path. I'm a bit unsure of where the problem is but try this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.