473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

I have an error. I am brain dead. Please give me a hint

9
What is the best checker to use to find these probles with, besides an experienced set of eyes?

This probram is to grade the response to input by user. Grades his marks.
Thanks
[HTML]
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Math Quiz</title>

<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function recordAnswer(question, answer) {
if (question = 1)
document.forms[0].studentAnswer1.value = answer;
else if (question = 2)
document.forms[0].studentAnswer2.value = answer;
else if (question = 3)
document.forms[0].studentAnswer3.value = answer;
}
var tooLong = false;
function scoreQuiz(){
if (tooLong == true)
alert("You ran out of time! You must retake the test by reloading the Web page.");
}
else if
{
if (document.forms[0].studentAnswer1.value == "" || document.forms[0].studentAnswer2.value == "" || document.forms[0].studentAnswer3.value == "") {
alert(You must answer all of the questions before scoring the quiz.);
return false;
}
var correct = 0;
if (document.forms[0].studentAnswer1.value == document.forms[0].answer1.value)
++correct;
if (document.forms[0].studentAnswer2.value == document.forms[0].answer2.value)
++correct;
if (document.forms[0].studentAnswer3.value == document.forms[0].answer3.value)
++correct;
alert("You scored " + correct + " answers correctly.");
}
return true;

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body onload="setInterval('tooLong=true;', 600000);">
<h1>Math Quiz</h1>
<p>Select the correct answer to the following math problems, then
select the Score Quiz button.</p>

<form action="" method="get" onsubmit="return scoreQuiz();">

<p><b>1.</b>&nbsp; 84 divided by 7 is equal to _____.</p>

<p><input type="radio" name="question1" value="6" onclick=
"recordAnswer(1, this.value);" />6<br />
<input type="radio" name="question1" value="7" onclick=
"recordAnswer(1, this.value);" />7<br />
<input type="radio" name="question1" value="9" onclick=
"recordAnswer(1, this.value);" />9<br />
<input type="radio" name="question1" value="12" onclick=
"recordAnswer(1, this.value);" />12</p>

<p><b>2.</b>&nbsp; What is the value of x in the equation <b>x * 12
= 156</b>.</p>

<p><input type="radio" name="question2" value="5" onclick=
"recordAnswer(2, this.value);" />5<br />
<input type="radio" name="question2" value="11" onclick=
"recordAnswer(2, this.value);" />11<br />
<input type="radio" name="question2" value="13" onclick=
"recordAnswer(2, this.value);" />13<br />
<input type="radio" name="question2" value="19" onclick=
"recordAnswer(2, this.value);" />19</p>

<p><b>3.</b>&nbsp; What is the square root of 196?</p>

<p><input type="radio" name="question3" value="7" onclick=
"recordAnswer(3, this.value);" />7<br />
<input type="radio" name="question3" value="14" onclick=
"recordAnswer(3, this.value);" />14<br />
<input type="radio" name="question3" value="28" onclick=
"recordAnswer(3, this.value);" />28<br />
<input type="radio" name="question3" value="98" onclick=
"recordAnswer(3, this.value);" />98</p>

<p><input type="submit" value=" Score Quiz" /></p>

<p><input type="hidden" name="answer1" value="12" /> <input type=
"hidden" name="answer2" value="13" /> <input type="hidden" name=
"answer3" value="14" /> <input type="hidden" name="studentAnswer1"
value="" /> <input type="hidden" name="studentAnswer2" value="" />
<input type="hidden" name="studentAnswer3" value="" /></p>
</form>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
</body>
</html>
[/HTML]

Edited by iam_clint: reason: Added html tags around your code do it for yourself from now on please. read posting guidelines.
Nov 16 '06 #1
7 1894
AricC
1,892 Expert 1GB
What do you mean by checker? A code validator? That will only make sure you have correct syntax. What problem are you having with this code?
Nov 16 '06 #2
511475
9
What do you mean by checker? A code validator? That will only make sure you have correct syntax. What problem are you having with this code?
Syntax problem. Something to do with "else if"
I thought there was something out there that would give me hints of what was wrong. Using word pad
Nov 16 '06 #3
iam_clint
1,208 Expert 1GB
Sloppy code let me fix it up.
Nov 16 '06 #4
511475
9
Thank you and thank for the direction to posting guide lines.
Nov 16 '06 #5
AricC
1,892 Expert 1GB
I use the Visual Studio Web Developer Express Edition it's free I can't remember how/if it validates javascript, but it isn't too shabby for a free product.


Aric
Nov 16 '06 #6
511475
9
I got it. I will have to learn it now. Thanks
just downloaded it at your suggestion
Nov 16 '06 #7
iam_clint
1,208 Expert 1GB
[HTML]
<html>
<title>Math Quiz</title>
<script>
var tooLong = false;

function recordAnswer(question, answer) {
if (question == 1) {
document.getElementById("studentAnswer1").value = answer;
}
if (question == 2) {
document.getElementById("studentAnswer2").value = answer;
}
if (question == 3) {
document.getElementById("studentAnswer3").value = answer;
}
}

function test() {
alert("test");
}

function scoreQuiz() {
allanswers = true;
if (document.getElementById("studentAnswer1").value == "" || document.getElementById("studentAnswer3").value == "" || document.getElementById("studentAnswer2").value == "") {
allanswers = false;
}
if (tooLong == true) {
alert("You ran out of time! You must retake the test by reloading the Web page.");
return false;
}
var correct = 0;
if (allanswers) {
if (document.getElementById("studentAnswer1").value == document.getElementById("answer1").value) {
++correct;
}
if (document.getElementById("studentAnswer2").value == document.getElementById("answer2").value) {
++correct;
}
if (document.getElementById("studentAnswer3").value == document.getElementById("answer3").value) {
++correct;
}
if (correct == 3) {
alert("You got all 3 correct!");
} else {
alert("You scored "+correct+" answers correctly.");
}
return true;
} else {
alert("You have to answer all questions!");
}
}

</script>
<body onload="setInterval('tooLong=true;', 600000);">

<h1>Math Quiz</h1>
<p>Select the correct answer to the following math problems, then
select the Score Quiz button.</p>

<p><b>1.</b>&nbsp; 84 divided by 7 is equal to _____.</p>

<p>
<input type="radio" name="question1" value="6" onclick="recordAnswer(1, this.value);">6<br>
<input type="radio" name="question1" value="7" onclick="recordAnswer(1, this.value);">7<br>
<input type="radio" name="question1" value="9" onclick="recordAnswer(1, this.value);">9<br>
<input type="radio" name="question1" value="12" onclick="recordAnswer(1, this.value);">12</p>
<p><b>2.</b>&nbsp; What is the value of x in the equation <b>x * 12
= 156</b>.</p>

<p><input type="radio" name="question2" value="5" onclick="recordAnswer(2, this.value);" />5<br />
<input type="radio" name="question2" value="11" onclick="recordAnswer(2, this.value);" />11<br />
<input type="radio" name="question2" value="13" onclick="recordAnswer(2, this.value);" />13<br />
<input type="radio" name="question2" value="19" onclick="recordAnswer(2, this.value);" />19</p>

<p><b>3.</b>&nbsp; What is the square root of 196?</p>

<p><input type="radio" name="question3" value="7" onclick="recordAnswer(3, this.value);" />7<br />
<input type="radio" name="question3" value="14" onclick="recordAnswer(3, this.value);" />14<br />
<input type="radio" name="question3" value="28" onclick="recordAnswer(3, this.value);" />28<br />
<input type="radio" name="question3" value="98" onclick="recordAnswer(3, this.value);" />98</p>

<p><input type="button" value=" Score Quiz" onclick="scoreQuiz();" /></p>

<p><input type="hidden" name="answer1" id="answer1" value="12" /> <input type="hidden" name="answer2" id="answer2" value="13" /> <input type="hidden" name="answer3" id="answer3" value="14" /> <input type="hidden" name="studentAnswer1" id="studentAnswer1" value="" /> <input type="hidden" name="studentAnswer2" id="studentAnswer2" value="" />
<input type="hidden" name="studentAnswer3" id="studentAnswer3" value="" /></p>
</body>
</html>
[/HTML]
Heres your fix I tried to not modify the code too much so you could see what is happening.
Nov 16 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for...
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
0
by: raghuveer | last post by:
i am a beginer to c progamming .Please give a list of some tricky quetions or links u have..it would be a great help
1
by: Ellen12c | last post by:
On the last post I asked about a code to make a vertical scroll bar and ends up I didn't need one. I was told by a big group of people on this forum that I needed to do away with all the flash and...
5
by: sreekalavinu | last post by:
I wish to include a search engine within my website.please give your thoughts
14
by: sudheerk | last post by:
please give me a query for already existing name in the data base using mysql
1
by: junglenut | last post by:
please give me a reverse word java program in a form of jcreator javax.swing.*; source code.. because i really have a hard time figuring it out on how to make it.. please give me a reverse word...
1
by: anoopev | last post by:
I want to read jad and jar files from generated location in my application. How do i do this? and after reading how it is send to email by button click action. Please give me immediate...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.