Randomly generate a test paper, the type of test paper is divided into radio, multi-choice, judging three types of questions. nodejs6.0 MySQL

Source: Internet
Author: User

Background: From the database, randomly generate a paper, the type of test paper is divided into radio, multi-choice, judging three types of questions.

First I need to generate a random number ID (before this I need to know the number of questions in the database, so that I can set the random number), and based on the generated random number ID, to find the corresponding topic. In the JS array operation, there are filter, splice, concat, every, find and so on. I need to get the specific data out of the database, and I'm going to return a set of objects, so I need to filter out a specific section.

The code is as follows:

var Danxuan = Getrandomnum (danxuan_count,20);
var Duoxuan = Getrandomnum (duoxuan_count,5);
var Panduan = Getrandomnum (panduan_count,10);
To save the generated random number to example,
var example = {Danxuan:danxuan.sort (sortnumber), Duoxuan:duoxuan.sort (Sortnumber), Panduan:panduan.sort (Sortnumber) }

Find a Database
Models. Answer.findall (). Then (function (Result) {
var danxuanlist = result.filter (t = t.exampletype== "single choice");//nodejs6.0 support
var duoxuanlist = result.filter (t = t.exampletype== "multi-choice");
var panduanlist = result.filter (t = = t.exampletype== "Judgment question");
New Object
var examplelist = {duoxuan:[],danxuan:[],panduan:[]};
Find the corresponding data in each list based on the randomly generated number ID.
Example.danxuan.forEach (function (i,v) {

ExampleList.danxuan.push (Danxuanlist[i]);
})
Example.duoxuan.forEach (function (i,v) {
ExampleList.duoxuan.push (Duoxuanlist[i]);
})
Example.panduan.forEach (function (i,v) {
ExampleList.panduan.push (Panduanlist[i]);
})
Res.json (examplelist);//test paper generation completed
});

Randomly generate a test paper, the type of test paper is divided into radio, multi-choice, judging three types of questions. nodejs6.0 MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.