The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Best way to build a quiz

4 posters

Go down

Best way to build a quiz Empty Best way to build a quiz

Post by Kami-sama May 16th 2018, 12:13 am

Hey all! I am trying to make a quiz with JS. The idea is that each answer gives certain amount of points to preset variables. In the end, result is the variable with most points. So I was thinking about going in this kind of style:

Code:

   var L=0,
      K=0,
      A=0,
      G=0,
      B=0,
      
      /* All answers to questions */
      a1="Answer1",
      a2="Answer2",
      a3="Answer3",
      
      b1="Answer1",
      b2="Answer2",
      b3="Answer3";
      
   var a = document.getElementById("question1answer").innerHTML;
      if (a == a1) { L+=4; K+=1; A+=2; G+=5; B+=3; }
      else if (a == a2) { L+=4; K+=5; A+=3; G+=1; B+=2; }
      else if (a == a3) { L+=4; K+=3; A+=1; G+=2; B+=5; }
      
   var b = document.getElementById("question2answer").innerHTML;
      if (b == b1) { L+=1; K+=2; A+=4; G+=5; B+=3; }
      else if (b == b2) { L+=1; K+=3; A+=5; G+=4; B+=2; }
      else if (b == b3) { L+=3; K+=1; A+=2; G+=4; B+=5; }

What would be the best way to set this up on front side? (CSS/HTML)
There are so many options I am not sure what could be the best for this case.
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Kami-sama May 18th 2018, 7:43 pm

up Smile
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Ritsu June 1st 2018, 11:00 am

What do you mean? Do you want a quiz template in HTML&CSS?
Ritsu
Ritsu
Forumember

Male Posts : 63
Reputation : 7
Language : Polish, English
Location : Poland

http://lolirock.forumpolish.com

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Kami-sama June 1st 2018, 12:37 pm

Ritsu wrote:What do you mean? Do you want a quiz template in HTML&CSS?
Kinda yes, exactly.
Not sure what is the best way of making quizzes.
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Ritsu June 1st 2018, 12:59 pm

There isn't the "best way". HTML&CSS are easy to learn, why wouldn't you write it on your own?
Ritsu
Ritsu
Forumember

Male Posts : 63
Reputation : 7
Language : Polish, English
Location : Poland

http://lolirock.forumpolish.com

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Kami-sama June 1st 2018, 4:12 pm

I would write it myself if I knew how, but I do not. That is why I am asking here for suggestions how this could be done with the style of test I am thinking of Smile
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Daemon June 4th 2018, 2:49 am

Would this questionnaire be to create a new topic or send a private message to the administrator?
Daemon
Daemon
Forumember

Posts : 104
Reputation : 91
Language : Português

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Kami-sama June 4th 2018, 7:02 pm

Daemon wrote:Would this questionnaire be to create a new topic or send a private message to the administrator?

You can think of it as test in a separate HTML page. Just listed questions with possible answer options.
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Daemon June 5th 2018, 12:00 am

Yes I understood! But when it is answered should it create a new topic or something like that?
Daemon
Daemon
Forumember

Posts : 104
Reputation : 91
Language : Português

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Kami-sama June 5th 2018, 12:57 am

Daemon wrote:Yes I understood! But when it is answered should it create a new topic or something like that?

I know what you are talking about, but no, that is not it Wink
Results will be either displayed on screen or just sent to my server
That's not really important part Smile
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by Daemon June 5th 2018, 1:22 am

In this simple example, the questionnaire sends the answer to the general administrator:
Code:
<div id="questionContainer">
  <div id="header">
      <h1>Questions</h1>
  </div>
  <ol id="left">
      <li>
        How much is 2+2?
        <div class="tab">
            <input type="radio" value="A" name="question1" />3<br />
            <input type="radio" value="B" name="question1" />1<br />
            <input type="radio" value="C" name="question1" />5<br />
            <input type="radio" value="D" name="question1" />4<br />
        </div>
      </li>
      <li>
        How much is 3x2?
        <div class="tab">
            <input type="radio" value="A" name="question2" />5<br />
            <input type="radio" value="B" name="question2" />6<br />
            <input type="radio" value="C" name="question2" />7<br />
            <input type="radio" value="D" name="question2" />8<br />
        </div>
      </li>
  </ol>
  <div id="buttonDiv">
      <input type="button" id="button" value="Send" />
  </div>
</div>
<style type="text/css">
#header {margin: 18px;}
#questionContainer li {margin-bottom: 20px;}
ol#left {margin-left: 20px;}
.tab {margin-top: 5px;}
</style>
<script type="text/javascript">
$(function() {
    var answers = [
        "4", "D",
        "6", "B"
    ];

    function calcScore() {
        var results = {
            right: 0,
            wrong: 0,
            answered: [],
            unanswered: [],
            missed: []
        };
        $("#questionContainer .tab").each(function(index) {
            var chosen = $(this).find("input:checked");
            if (chosen.length) {
                results.answered.push(index);
                if (chosen.val() == answers[(index * 2) + 1]) {
                    results.right++;
                    results.answered.push(index);
                } else {
                    results.wrong++;
                    results.missed.push(index);
                }
            } else {
                results.unanswered.push(index);
            }
        });
        return (results);
    }

    $(document).on("click", "#button", function() {
        var results = calcScore();
        var str = "Correct: " + results.right + ", Wrong: " + results.wrong + ", Unanswered: " + results.unanswered.length;
        $.post('/privmsg', {
            folder: 'inbox',
            mode: 'post',
            post: '1',
            usergroup: '1',
            subject: 'Quiz - Answers',
            message: '[b]Result:[/b] ' + str
        }).done(function() {
            alert("Replies sent");
        }).fail(function() {
            alert("Error! No replies were sent");
        });
    });
});
</script>
Daemon
Daemon
Forumember

Posts : 104
Reputation : 91
Language : Português

Back to top Go down

Best way to build a quiz Empty Re: Best way to build a quiz

Post by SLGray June 13th 2018, 8:12 am

hiphopza wrote:Love this forum
Please do not post in support topics unless you are offering a solution or asking for help.


Best way to build a quiz Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51555
Reputation : 3524
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum