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.
    SEMrush



    <html>
    <body>
    <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'],
    ['Wright','Henry@','Bergkamp'],
    ['Red and White@','Yellow','Black'],
    ['Wenger@','Taylor','Rioch'],
    ['Real Madrid','Barcelona@','Liverpool'],
    ['German','Dutch@','French'],
    ['Clichy','Vermaelen','Fabregas@'],
    ['Second',' Third@','Fourth'],
    ['Nottingham','Birmingham','London@']];

    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=document.createElement("input");
    r.type="radio";
    r.name="Q" + i;
    r.value=answers[i2];
    document.body.appendChild(r);
    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) {
    userAnswers.push(rads.value);
    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
    }
    document.body.appendChild(b);
    </script>
    </body>
    </html>
     
    Walcott14, Aug 17, 2010 IP
    SEMrush
  2. Logic Ali

    Logic Ali Active Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    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