Click here to Skip to main content
14,356,475 members

JavaScript

 
GeneralRe: How to activate button on mouse press? Pin
samflex6-Jun-19 10:47
membersamflex6-Jun-19 10:47 
Questionhow to count product codes from textarea? Pin
Veltix26-May-19 5:11
memberVeltix26-May-19 5:11 
AnswerRe: how to count product codes from textarea? Pin
jkirkerx27-May-19 12:14
professionaljkirkerx27-May-19 12:14 
QuestionBest ReactJS tutorial? Pin
Corey Cananza26-May-19 4:59
memberCorey Cananza26-May-19 4:59 
AnswerRe: Best ReactJS tutorial? Pin
Katie Webber30-Jul-19 3:06
professionalKatie Webber30-Jul-19 3:06 
AnswerRe: Best ReactJS tutorial? Pin
Harsh.Shah.ifour13-Aug-19 19:13
groupHarsh.Shah.ifour13-Aug-19 19:13 
AnswerRe: Best ReactJS tutorial? Pin
Le centriste4-Sep-19 4:57
memberLe centriste4-Sep-19 4:57 
QuestionHow to call function second time? Pin
Tarun Rathore 23-May-19 20:28
memberTarun Rathore 23-May-19 20:28 
I have coding of a quiz with an array which has questions and options. First time the function is called successfully but when restarting the quiz, the function is not invoked.
This is the code which is not working:
$(document).on('click', '#restart', function() {
     showQuestions();
 });


The whole coding is:

// Showing questions and options

 var x = "";
 var i = 0;

 function showQuestions() {
 document.getElementById('holder').
 innerHTML = x;

for (j = 0; j < words[i].options.length; j++) {
    if (i < words.length) {
       $('#holder').append("<div 
       id="+words[i].options[j] + " 
       class='alternatives'>" + 
       words[i].options[j] + "
       </div>");
       }
     }
      if (i < words.length) {
         $('#holder').append('<div 
         id="quest">' + 
         words[i].question + '</div>');
         i++;
     }
 }

 showQuestions();


// Calling function on click of alternatives
 $('#holder').on('click', 
'.alternatives', function() {
     showQuestions();
});

 // Checking answers

    score = 0;
    k = 0;

 $(document).on('click', 
'.alternatives', function() {
     let guess = this.id;
     if (k < words.length) {
    var correct = words[k].answer;
         k++;
     }
     if (guess === correct) {
         score++;
     }

     if (score <= words.length) {
         z = score;
         document.getElementById('summary').innerHTML = z;
     }

     if (k >= words.length) {
         $('#holder').fadeOut();
         $('#restart').fadeIn();
     }
 });


// Restarting Quiz
$(document).on('click', '#restart', function() {
    $(this).fadeOut();
    $('#holder').fadeIn();
    showQuestions();
});


modified 24-May-19 7:53am.

GeneralRe: How to call function second time? Pin
Richard MacCutchan23-May-19 22:56
protectorRichard MacCutchan23-May-19 22:56 
AnswerRe: How to call function second time? Pin
Shraddha_Patel21-Oct-19 21:04
memberShraddha_Patel21-Oct-19 21:04 
QuestionExplain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any? Pin
Shraddha_Patel20-May-19 18:38
memberShraddha_Patel20-May-19 18:38 
AnswerRe: Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any? Pin
Richard MacCutchan20-May-19 22:03
protectorRichard MacCutchan20-May-19 22:03 
AnswerRe: Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any? Pin
ZurdoDev21-May-19 3:03
professionalZurdoDev21-May-19 3:03 
QuestionHow to give unique ids to changing divs? Pin
Tarun Rathore 18-May-19 10:48
memberTarun Rathore 18-May-19 10:48 
AnswerRe: How to give unique ids to changing divs? Pin
ZurdoDev21-May-19 3:04
professionalZurdoDev21-May-19 3:04 
QuestionUsing XML Pin
V.28-Apr-19 21:57
professionalV.28-Apr-19 21:57 
SuggestionRe: Using XML Pin
Richard MacCutchan28-Apr-19 22:56
protectorRichard MacCutchan28-Apr-19 22:56 
GeneralRe: Using XML Pin
V.28-Apr-19 23:21
professionalV.28-Apr-19 23:21 
GeneralRe: Using XML Pin
Richard MacCutchan28-Apr-19 23:25
protectorRichard MacCutchan28-Apr-19 23:25 
GeneralRe: Using XML Pin
V.28-Apr-19 23:38
professionalV.28-Apr-19 23:38 
AnswerRe: Using XML Pin
Graham Breach29-Apr-19 3:35
memberGraham Breach29-Apr-19 3:35 
GeneralRe: Using XML Pin
V.30-Apr-19 2:38
professionalV.30-Apr-19 2:38 
Question<SOLVED> Why is my validation script not working? Pin
samflex26-Apr-19 5:20
membersamflex26-Apr-19 5:20 
AnswerRe: Why is my validation script not working? Pin
Richard Deeming26-Apr-19 5:31
mveRichard Deeming26-Apr-19 5:31 
GeneralRe: Why is my validation script not working? Pin
samflex26-Apr-19 5:45
membersamflex26-Apr-19 5:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.