Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

What is wrong with this?


  • Please log in to reply

#1
A Train

A Train

    Member

  • Member
  • PipPip
  • 70 posts
This is what I have for my webpage quiz. Can somebody tell me what is wrong? At the bottom of the page when I click on 'get score' it comes up with error on page.

Anybody?


<html>
<head>
<title>Sports injuries</title>
<LINK REL="stylesheet" TYPE="text/css" HREF="WCcss.css">
<script language="JavaScript">
<!--

var numQues = 10;
var numChoi = 4;

var answers = new Array(10);
answers[0] = "3";
answers[1] = "Compression";
answers[2] = "Direct injuries";
answers[3] = "400+";
answers[4] = "Cardiac muscle";
answers[5] = "30 Seconds";
answers[6] = "Above heart";




function getScore(form) {
var score = 0;
var currElt;
var currSelection;

for (i=0; i<numQues; i++) {
currElt = i*numChoi;
for (j=0; j<numChoi; j++) {
currSelection = form.elements[currElt + j];
if (currSelection.checked) {
if (currSelection.value == answers[i]) {
score++;
break;
}
}
}
}

score = Math.round(score/numQues*100);
form.percentage.value = score + "%";

var correctAnswers = "";
for (i=1; i<=numQues; i++) {
correctAnswers += i + ". " + answers[i-1] + "\r\n";
}
form.solutions.value = correctAnswers;

}

// -->
</script>



<font class="normal" color="black">
<form name="quiz">
1. How many different <b>types</b> of muscles does your body have?<br>
<input type="radio" name="q1" value="1">1 <br>
<input type="radio" name="q1" value="2">2<br>
<input type="radio" name="q1" value="3">3<br>
<input type="radio" name="q1" value="4">4<br>
<p>

2. What does 'C' stand for in RICE?
<br>
<input type="radio" name="q2" value="Low Frequency Wave">Contact<br>
<input type="radio" name="q2" value="Transverse Wave">Consume<br>
<input type="radio" name="q2" value="High Frequency Wave">Compression<br>
<input type="radio" name="q2" value="Longitudinal wave "> Cartilage<br>
<p>

3. What injury results from a blunt trauma?<br>
<input type="radio" name="q3" value="Direct injuries">Direct injuries<br>
<input type="radio" name="q3" value="Indirect injuries">Indirect injuries<br>
<input type="radio" name="q3" value="Acute injuries">Acute injuries<br>
<input type="radio" name="q3" value="Chronic injuries">Chronic injuries<br>
<p>

4. How many muscles does your body have?<br>
<input type="radio" name="q4" value="We hear louder sound">20-30<br>
<input type="radio" name="q4" value="We hear higher pitched sound">100-200<br>
<input type="radio" name="q4" value="We hear lower pitched sound">400+<br>
<input type="radio" name="q4" value="We hear quiter sound">200-300<br>
<p>

5. What is your heart musscle called?<br>
<input type="radio" name="q5" value="Gracilis muscle">Gracilis muscle<br>
<input type="radio" name="q5" value="Cardiac muscle">Cardiac muscle<br>
<input type="radio" name="q5" value="Sartorius muscle">Sartorius muscle<br>
<input type="radio" name="q5" value="Soleus muscle">Soleus muscle<br>
<p>

6. What is the best amount of time to stretch each muscle for?<br>
<input type="radio" name="q6" value="Infrasound">10 Seconds<br>
<input type="radio" name="q6" value="Ultrasound">15 Seconds<br>
<input type="radio" name="q6" value="Gammasound">20 Seconds<br>
<input type="radio" name="q6" value="Deltasound">30 Seconds<br>
<p>

7. How high should you raise an injury?<br>
<input type="radio" name="q7" value="Above knee level">Above knee level<br>
<input type="radio" name="q7" value="Above shoulder">Above shoulder<br>
<input type="radio" name="q7" value="Above heart">Above heart<br>
<input type="radio" name="q7" value="Above the injury">Above the injury<br>
<p>



<input type="button" value="Get score" onClick="getScore(this.form)">
<input type="reset" value="Clear"><p>
Score = <input type=text size=15 name="percentage"><br>
Correct answers:<br>
<textarea name="solutions" wrap="virtual" rows="4" cols="40"></textarea>
</form>
  • 0

Advertisements


#2
puterman

puterman

    Member

  • Member
  • PipPip
  • 67 posts
Try this, it appears you have a value of 10 questions but your quiz only has 7. make the following changes in your code and it should work.


var numQues = 7;
var numChoi = 4;

var answers = new Array(7);
answers[0] = "3";
answers[1] = "Compression";
answers[2] = "Direct injuries";
answers[3] = "400+";
answers[4] = "Cardiac muscle";
answers[5] = "30 Seconds";
answers[6] = "Above heart";


Let me know if all works out.

Joe V aka Puterman
  • 0

#3
A Train

A Train

    Member

  • Topic Starter
  • Member
  • PipPip
  • 70 posts
Oh well done, that fixed it. I had coppied it from my last quiz and must have missed that.

Thanks,
Aaron
  • 0

#4
puterman

puterman

    Member

  • Member
  • PipPip
  • 67 posts
My pleasure, glad I could lend a hand! Sometimes it is easier to find the little things with fresh eyes. I am sure after a good nights sleep it would have jumped out at you.

Have a good one!

Joe V aka puterman
  • 0

#5
A Train

A Train

    Member

  • Topic Starter
  • Member
  • PipPip
  • 70 posts
You up for another problem? Heres hoping...

The score is all messed up, no matter what happens the % of the correct unswers is really low. Unrealisticly low.

Anybody?
  • 0

#6
puterman

puterman

    Member

  • Member
  • PipPip
  • 67 posts
A Train,

If you look at your code, where you list the questions/answers, your values are not matching. Thus the script does not recognize the correct check mark cause the value of the answer does not match:

1. How many different <b>types</b> of muscles does your body have?<br>
<input type="radio" name="q1" value="1">1 <br>These are Correct
<input type="radio" name="q1" value="2">2<br>
<input type="radio" name="q1" value="3">3<br>
<input type="radio" name="q1" value="4">4<br>
<p>

2. What does 'C' stand for in RICE?
<br>
<input type="radio" name="q2" value="Low Frequency Wave">Contact<br>These do not match
<input type="radio" name="q2" value="Transverse Wave">Consume<br>
<input type="radio" name="q2" value="High Frequency Wave">Compression<br>
<input type="radio" name="q2" value="Longitudinal wave "> Cartilage<br>
<p>


Just go through your questions/answers and correct the values and all should work fine.

Joe V aka Puterman
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP