Jump to content

Hi all, this is my problem. 

 

im making a website that is a tutorial for new starts on a particular subject. the site should have information to read through and the a quiz on what they've read ( this is where i'm strugglin) and a feedback page.

 

The quiz should have :2 multi choice questions, 2 true and false questions and 2 fill in the blank questions. from the answers given the score should be available on the a feedback page with a breakdown on whats happened, correct answers and wrong answers.  with the wrong answer it would be good to point the user back towards the important part of the website to re read the topic.

 

Im struggling with linking a javascript file to the html file so that the inputs from the above questions are recorded and score given. 

 

 

any help would be greatly appreciated 

 

regards

 

peaky101

Link to comment
https://linustechtips.com/topic/266491-html-and-javascript-quiz/
Share on other sites

Link to post
Share on other sites

Hi all, this is my problem. 

 

im making a website that is a tutorial for new starts on a particular subject. the site should have information to read through and the a quiz on what they've read ( this is where i'm strugglin) and a feedback page.

 

The quiz should have :2 multi choice questions, 2 true and false questions and 2 fill in the blank questions. from the answers given the score should be available on the a feedback page with a breakdown on whats happened, correct answers and wrong answers.  with the wrong answer it would be good to point the user back towards the important part of the website to re read the topic.

 

Im struggling with linking a javascript file to the html file so that the inputs from the above questions are recorded and score given. 

 

 

any help would be greatly appreciated 

 

regards

 

peaky101

What have you tried so far? Post your code using the code tags.

 

http://stackoverflow.com/help/how-to-ask

http://mattgemmell.com/what-have-you-tried/

Link to comment
https://linustechtips.com/topic/266491-html-and-javascript-quiz/#findComment-3620502
Share on other sites

Link to post
Share on other sites

 

ive so far tried to look around the web and 'fit' codes to the problem but i haven't had any luck.

 

<div> 1) what is this question</div>
        <input type="radio" value="a" name="question1">a) .<br>
        <input type="radio" value="b" name="question1">b) <br>
        <input type="radio" value="c" name="question1">c) <br>
        <input type="radio" value="d" name="question1">d) <br>
        
         <div> 1) what is this question</div>
        <input type="radio" value="a" name="question2">a) <br>
        <input type="radio" value="b" name="question2">b) <br>
        <input type="radio" value="c" name="question2">c) <br>
        <input type="radio" value="d" name="question2">d) <br>
 
this is my multi choice html code.
 
i'm struggling to link a javascript file to it so that takes the inputs from it and allows me to print the score into a feedback page.
Link to comment
https://linustechtips.com/topic/266491-html-and-javascript-quiz/#findComment-3620538
Share on other sites

Link to post
Share on other sites

You need to close the tag 

<script type="text/javascript" src="test.js"></script>.

 

The type attribute is necessary for html4 but defaults to javascript in html5. I generally use it for compatibility.

Gaming Rig: i5-3570k+H100i (4.3 ghz) | P8Z77-i Deluxe | MSI Twin Frozr 7950 Boost | HX650 | 1TB HGST | 840 Evo 250 GB

Link to comment
https://linustechtips.com/topic/266491-html-and-javascript-quiz/#findComment-3620584
Share on other sites

Link to post
Share on other sites

thank you for clearing that up.

 

So the user clicks on the quiz and answers the two questions. how do i get the javascript to check the questions against the right answers ? so far i have 

 

var numberofquestions=2
 
var answers=new Array()
answers[1]='a'
answers[2]='b'
Link to comment
https://linustechtips.com/topic/266491-html-and-javascript-quiz/#findComment-3620625
Share on other sites

Link to post
Share on other sites

wrap all your input tags in a form. add a submit button to the form. 

Use the array literal method of creating an answers array.

var answers = [a,b,c,d];

Arrays start counting with 0 so answers[0] would be a.

onto the onclick listener to the button, call a function that sees which ones are checked.

So basically you want to check if the user's answer you would want to check to see what value is checked.

You can get an array of elements with name question1 with the following code. So

document.getElementsByName("question1")[0].checked

would return true if the radio was selected.

Using a for loop you can iterate through all the elements with question1 name and see which ones are selected. Do the same with question 2

and then now that you got the ones which are selected, you can use if logic or whatever to determine what to do withem.

Gaming Rig: i5-3570k+H100i (4.3 ghz) | P8Z77-i Deluxe | MSI Twin Frozr 7950 Boost | HX650 | 1TB HGST | 840 Evo 250 GB

Link to comment
https://linustechtips.com/topic/266491-html-and-javascript-quiz/#findComment-3620772
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×