Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5949043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:11:38+00:00 2026-05-22T17:11:38+00:00

Today I’m trying to improve a Jeopardy-style game for work using ColdFusion, HTML, and

  • 0

Today I’m trying to improve a Jeopardy-style game for work using ColdFusion, HTML, and Javascript. As it stands now, the game navigates to a question page which displays the question along with an answer box for the user to type in their response. We’re trying to change this to a multiple-choice quiz, instead.

The main thing I want to achieve is to have the three possible answers be displayed in random order. The database that the game pulls from has 4 attributes relevant to this, as follows:

MC_Question

MC_CorrectAnswer

MC_IncorrectAnswer1

MC_IncorrectAnswer2

I want the question page/popup to display:


MC_Question

Randomly selected Answer1

Randomly selected Answer2

Randomly selected Answer3

Submit button


I’ve created a teensy little bit of html with some randomly generated numbers that might give you a better idea of where I’m trying to go with this.

<HTML>
<HEAD>
<TITLE>Question</TITLE>
<script>
    var num=Math.floor(Math.random()*3); 

    var num1=Math.floor(Math.random()*3); 
    do{
    num1=Math.floor(Math.random()*3); 
    }while (num == num1) 

    var num2=Math.floor(Math.random()*3); 
    do{
    num2=Math.floor(Math.random()*3); 
    }while (num == num2 || num1 == num2)
</script>
</HEAD>
<BODY>
<H1>Question here!</H1>
<P>
<FORM>
    <INPUT type="radio" name = "Answer" value="num" />
    <script>document.write("Answer " + num);</script><br />

    <INPUT type="radio" name = "Answer" value="num1" />
    <script>document.write("Answer " + num1);</script><br />

    <INPUT type="radio" name = "Answer" value="num2" />
    <script>document.write("Answer " + num2);</script><br />
    <br>
    <input type="submit" value="Submit" />
</FORM>
</BODY>
</HTML>

My question is this: how do I tie my database answers into my randomly generated numbers to mix up the answers? In the example code above, Answer 0 would equal MC_CorrectAnswer, and answers 1 and 2 would be the incorrect ones. I’ll worry about the submission stuff etc. later- for now I just want the form to display the question and answers pulled from the DB.

I’m very new to Javascript and CF, and any input you have is greatly appreciated. If I’m going about this in completely the wrong way, please let me know.

I also took a look at this Q and A, and to address that I’d like to say that I’m happy to create a separate table for answers, with incorrect/correct flags, etc, if necessary, but what I’m really looking for here is the front-end code and logic to randomize my questions on the page. The back-end goodies don’t even exist yet.

Randomizing -and remembering that randomisation- multiple choice questions in php

Thanks so much for your time and expertise!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:11:38+00:00Added an answer on May 22, 2026 at 5:11 pm

    Use java.util.Collections.shuffle(list).

    <!--- simulate a database <cfquery>SELECT id, answer FROM answers</cfquery> call --->
    <cfset answers = QueryNew("id,answer","integer,varchar")>
    <cfloop from="1" to="3" index="idx">
        <cfset queryAddRow(answers)>
        <cfset querySetCell(answers, "id", idx)>
        <cfset querySetCell(answers, "answer", "Answer #idx#")>
    </cfloop>
    
    <cfset rownumbers = []>
    <cfloop from="1" to="#answers.recordcount#" index="rowNumber">
        <cfset arrayAppend(rowNumbers, rowNumber)>
    </cfloop>
    
    <cfset createObject("java", "java.util.Collections").shuffle(rowNumbers)>
    
    <cfdump var="#rowNumbers#">
    
    <cfoutput>
    <body>
    <h1>Question here!</h1>
    <p>
    <form>
        <cfloop array="#rowNumbers#" index="rowNumber">
            <input type="radio" name="answerId" value="#answers.id[rowNumber]#" />#answers.answer[rowNumber]#<br />
        </cfloop>
    </form>
    </body>
    </cfoutput>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At work today we were trying to come up with any reason you would
Today I am trying to echo this php mysql statement within my javascript code,
I ran into a problem today when trying to set a field using FieldInfo.SetValue()
Here is what I'm struggling with today: I'm trying to draw a graph using
Total newbie question here...Today while trying to calculate sum of a list of integers(actually
today I was trying something using 'lib cURL' when I got this weird error,
I just ran into LINQPad today and was trying to add a connection using
I just bumped on to this question today and was trying for a solution
Back with my daily silly question. Today I'm trying to put a struct in
I was today trying to figure out on working with WebService and found many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.