26 Replies - 4162 Views - Last Post: 26 July 2013 - 06:01 PM

Creating an Online Quiz

Posted 03 July 2013 - 11:57 AM

Ok so I'm trying to create an online quiz that's completely random, but being so, how can I find the correct answer to match with the picture? I'm very new to Javascript and web programming, so please bare with me. This is what I have, but how can I get the correct answer instead of just assigning a specific radio to be the correct answer?
Where am I going wrong?

My idea is to create a 20 question quiz (where the question is just an image). I have 4 radio buttons with answers (that randomize with reload and "next" button (which I haven't done the next button yet). I have to match at least one of the random radio buttons with the correct answer but I'm confused on how to get that part. I also have to do a score at the end and highlight the correct answer, but baby steps... I'll figure that out later. Anyone that can help? It is greatly appreciated.

Re: Creating an Online Quiz

Posted 18 July 2013 - 06:43 PM

Hi, unfortunately I'm still confused and didn't really understand your response.
I did however clean up my file a bit, but I'm still stuck on how to get both arrays to read each other or "compare" so I can get the correct Answer from the radio buttons. Maybe I'm just reading too into it, and not going at it the right way? I would appreciate some coding help to get this function working and get this program to work. I still have a few more steps to go after the randomizing part (I need to score the correct answers at the end too!). Anyway this is what I have so far:

Re: Creating an Online Quiz

Posted 18 July 2013 - 07:18 PM

For the choices, all of the buttons should have names that were randomly chosen from among the names in that go with other pictures (I have two arrays). One of the choices (but not always the same one) should be the correct answer. Which button holds the correct answer should also be randomly chosen (hence, why everything is randomized). When the user has selected a choice, the page should display something to indicate correct or incorrect (alerts).

Clicking on the “correct answer” button should highlight the choice that was correct (haven't gotten to this part yet). Clicking on the “Next” button should set up the next challenge. There is no need for a start or restart button. The user just has to reload the page. Ideally, when the page is first loaded, it should create a random ordering in which to show the images. That way, each time to the user reloads the page, they will be shown the images in a different order.

Re: Creating an Online Quiz

Posted 19 July 2013 - 08:28 AM

Still having a hard time trying to get the correct answer. This is the last part of my project, but I'm at a blank at this point. I tried adding more code to check the answer, but it's not working. Can someone assist me in fixing this section so I can get it to read the correct answer and score?

Re: Creating an Online Quiz

Posted 20 July 2013 - 09:17 AM

I'm stuck on the code. Can someone actually tell me where I'm wrong in the javascript code?
I can't get it to run. I need code to figure out where I'm going wrong. I know what I need to do for it, I'm just stuck on the code. Where am I going wrong?

Re: Creating an Online Quiz

Posted 20 July 2013 - 02:06 PM

I don't have the answer to your current code-issue but I can offer some advice about how I might approach this. Feel free to ignore most of this if you want to continue with your code as-is (particularly as I haven't studied your code in detail.)

All of your images are coming from the same location. I would move this location to a separate variable, and just add it back in when displaying the images. This will make the code easier to read and, therefore, to maintain.

var locn = "http://upload.wikimedia.org/wikipedia/commons/";

I would create an array of objects. Each object would have properties for the image-src (without the location), and the correct answer.

I would create an array and put the correct answer into it. Then I would randomly select 3 other answers, each time checking that it wasn't the correct answer (which is already in the array) or another answer that has already been chosen. That is, randomly select an answer, but check each time that it isn't already in the answers' array. Then create random numbers 0..3 to place these possible answers in random order on the page.

When the user answers the question we can just check whether this is the correct answer stored in the original array. We need a variable as well to remember which question we are currently asking.

Anyway, good luck.

PS This approach also has the added advantage of not using parallel arrays, which may be the root-cause of your issues.