Click here to Skip to main content
15,881,424 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: How to activate button on mouse press? Pin
samflex6-Jun-19 9:47
samflex6-Jun-19 9:47 
Questionhow to count product codes from textarea? Pin
Veltix26-May-19 4:11
Veltix26-May-19 4:11 
AnswerRe: how to count product codes from textarea? Pin
jkirkerx27-May-19 11:14
professionaljkirkerx27-May-19 11:14 
QuestionBest ReactJS tutorial? Pin
Corey Cananza26-May-19 3:59
Corey Cananza26-May-19 3:59 
AnswerRe: Best ReactJS tutorial? Pin
Katie Webber30-Jul-19 2:06
professionalKatie Webber30-Jul-19 2:06 
AnswerRe: Best ReactJS tutorial? Pin
Harsh.Shah.ifour13-Aug-19 18:13
professionalHarsh.Shah.ifour13-Aug-19 18:13 
AnswerRe: Best ReactJS tutorial? Pin
Le centriste4-Sep-19 3:57
Le centriste4-Sep-19 3:57 
QuestionHow to call function second time? Pin
Tarun Rathore 23-May-19 19:28
Tarun Rathore 23-May-19 19: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 21:56
mveRichard MacCutchan23-May-19 21:56 
AnswerRe: How to call function second time? Pin
Shraddha_Patel21-Oct-19 20:04
Shraddha_Patel21-Oct-19 20:04 
QuestionExplain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any? Pin
Shraddha_Patel20-May-19 17:38
Shraddha_Patel20-May-19 17:38 
AnswerRe: Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any? Pin
Richard MacCutchan20-May-19 21:03
mveRichard MacCutchan20-May-19 21:03 
AnswerRe: Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any? Pin
ZurdoDev21-May-19 2:03
professionalZurdoDev21-May-19 2:03 
QuestionHow to give unique ids to changing divs? Pin
Tarun Rathore 18-May-19 9:48
Tarun Rathore 18-May-19 9:48 
AnswerRe: How to give unique ids to changing divs? Pin
ZurdoDev21-May-19 2:04
professionalZurdoDev21-May-19 2:04 
QuestionUsing XML Pin
V.28-Apr-19 20:57
professionalV.28-Apr-19 20:57 
SuggestionRe: Using XML Pin
Richard MacCutchan28-Apr-19 21:56
mveRichard MacCutchan28-Apr-19 21:56 
GeneralRe: Using XML Pin
V.28-Apr-19 22:21
professionalV.28-Apr-19 22:21 
GeneralRe: Using XML Pin
Richard MacCutchan28-Apr-19 22:25
mveRichard MacCutchan28-Apr-19 22:25 
GeneralRe: Using XML Pin
V.28-Apr-19 22:38
professionalV.28-Apr-19 22:38 
AnswerRe: Using XML Pin
Graham Breach29-Apr-19 2:35
Graham Breach29-Apr-19 2:35 
GeneralRe: Using XML Pin
V.30-Apr-19 1:38
professionalV.30-Apr-19 1:38 
Question<SOLVED> Why is my validation script not working? Pin
samflex26-Apr-19 4:20
samflex26-Apr-19 4:20 
AnswerRe: Why is my validation script not working? Pin
Richard Deeming26-Apr-19 4:31
mveRichard Deeming26-Apr-19 4:31 
GeneralRe: Why is my validation script not working? Pin
samflex26-Apr-19 4:45
samflex26-Apr-19 4: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.