1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript Code Help

Discussion in 'JavaScript' started by Walcott14, Aug 17, 2010.

  1. #1
    Ive got this code and put comments on somethings I understand I dont understand the middle section, could someone comment the rest so I know what it means for future reference when looking back at it. Not sure if what I've put so far is correct so would appreciate it if its flagged up. Appreciate the help once again.

    <script type="text/javascript">
    var questions = ['What colour was Arsenals First Kit?', //Array Questions
    'Arsenals Stadium Name?',
    'Arsenals Top Scorer?',
    'Arsenal Team Colours?',
    'Arsenals Manager?',
    'Who did they lose to in the Championsleague Final?',
    'What nationalilty is Robin van Persie?',
    'Arsenals Captain?',
    'Where did Arsenal Finish Last Season?',
    'Where are Arsenal based?'];

    var answers = [['Red','White','Redcurrent@'], //Array Answers
    ['Wembley','Emirates Stadium@','Highbury'],
    ['Red and White@','Yellow','Black'],
    ['Real Madrid','Barcelona@','Liverpool'],
    ['Second',' Third@','Fourth'],

    var userAnswers = new Array();
    var r;

    for(i=0;i<questions.length;i++) {
    document.body.innerHTML += ("<b>" + questions + "</b><br>");
    for(i2=0;i2<answers.length;i2++) {
    r.name="Q" + i;
    document.body.innerHTML+=(answers[i2].replace("@","") + "<br>"); //Displays answers to screen
    var b = document.createElement("input");
    b.type = "button";
    b.value = "Check my answers";
    b.onclick = function() {
    var rads = document.getElementsByTagName("input");
    var correct = 0;
    for(i=0; i<rads.length; i++) {
    if(rads.type=="radio" && rads.checked) {
    if(rads.value.search("@")>-1) correct += 1;
    var p = (correct /(questions.length)) * 100 //variable to work out percentage
    window.alert("you got " + p + "% correct");//Displays percentage
    window.alert("you got " + correct + " out of" + (questions.length) );//Displays Score
    Walcott14, Aug 17, 2010 IP
  2. Logic Ali

    Logic Ali Active Member

    Likes Received:
    Best Answers:
    Trophy Points:
    That's something you might do with your own code, but why do it to someone else's code when its clear what it does just by running it?
    I'm pretty sure I know the answer.
    Logic Ali, Aug 17, 2010 IP