Need help debugging a javascript?

Are you good at JavaScript? If so I need help!?

  • I am making a quiz where when you hit submit a JavaScript window pops up saying if you either correct or incorrect. Click on this link to see what i am talking about. http://peanutspace.com/chee/dropdown1.html as you can see that when you hit submit on each page the answer is always red. what i need help with is making the second page answer pop up that says the answer is green and the third as blue.. can any one help me? here is the JavaScript code var n = 16; // modify this for number of seconds to answer document.getElementById( 'time').value = "Answer in " + n + " seconds"; var i = setInterval('count()' , 1000); var tooLate; function count() { tooLate = 0; n--; if(n >=0) { document.getElementById( 'time').value = "Answer in " + n + " seconds"; } else { clearInterval(i); alert("Too late!"); document.getElementById('answer').valu… = ""; tooLate = 1; } } //array of right answers var ans=new Array(); ans[0]="green"; ans[1]="blue"; ans[2]="red"; function answer(question) { var correct = ans[2]; // This is the correct answer if (tooLate == 0) { if(document.getElementById( 'answer').value == correct) { clearInterval(i); alert("Right Answer with " + n + " seconds remaining"); } else{ clearInterval(i); alert("Incorrect! The answer was " + correct); } } submitform(); function submitform() { document.forms["myform"].submit(); } } if you need the html code for reference just view source code on that link i posted Thank you!!

  • Answer:

    The reason for this is found here: var correct = ans[2]; // This is the correct answer You specify which answer is correct. What you need to do is this: var correct = ans[x]; Now, for each question, you need to add a line like this BEFORE the linked script.js script: <script type="text/javascript"> var x = 2; // 2 for ketchup, 1 for sky, 0 for grass </script> Now, the linked script.js will inherit the value of x from your inline script on each page, thereby select the correct answer. I think this should solve your problem.

skateman... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.