Results 1 to 2 of 2

Thread: Javascript Help

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1
    Thanks
    0
    Thanked
    0 times in 0 posts

    Javascript Help

    var Question = function(id, text, correct, incorrect){
    this.id = id;
    this.text = text;
    this.all = incorrect;
    this.all.push(correct);
    this.all.sort(randomSort);
    }

    Question.prototype.write = function(){
    var qu = document.getElementById("questions");
    qu.innerHTML += "<p>" + this.text + "</p>";

    var questionList = "<ul class='questionlist'>";
    for (var i = 0; i < this.all.length; i++) {
    if (this.all[i] == this.correct) {

    questionList += "<li><input type='checkbox' name='" + this.id + "'>" + this.all[i] + "</input></label></li>";

    }
    else {

    questionList += "<li><input type='checkbox' name='" + this.id + "'>" + this.all[i] + "</input></label></li>";
    }
    }
    questionList += "</ul>";
    qu.innerHTML += questionList;
    }

    var randomSort = function(a, b){
    return Math.random() * 100 - 50;
    }


    var q1 = new Question("q1", "Which of these cities has been around the longest?", "Athens", ["Krakow", "London", "Rome"]);
    var q2 = new Question("q2", "What city is nearest the equator?", "London", ["Amsterdam", "Berlin", "Warsaw"]);
    var q3 = new Question("q3", "What is the capital of Peru?", "Lima", ["Ancash", "Cusco", "La Paz"]);
    var q4 = new Question("q4", "As of 2010 which is the most populated city?", "Tokyo", ["Sao Paolo", "Los Angeles", "London"]);

    var questions = [q1, q2, q3, q4].sort(randomSort);

    for (var i = 0; i < 3; i++) {
    questions[i].write();
    questions.splice(rnd)
    }

    function load() {
    var load = window.open('cw2.htm','','scrollbars=yes,menubar=yes,height=600,width=600,resizable=yes,toolbar=no,l ocation=no,status=no');
    }

    Quiz

    1.)This writes a random question to the page and provides a check box, however i would like to be able to provide immediate feedback, for example, when they check the box I can display in writing weather what they chose was wrong

    2.) My function down the bottom opens a new windows with another new question, however the question somtimes repeats I need to somehow keep the questions random, the .sort math random function does this, but as im loading in a new window the JS starts over again and so arrays already been used are back in

    Any help would be much aprreciated. I know I am brand new just looking for a lifeline

  2. #2
    cat /dev/null streetster's Avatar
    Join Date
    Jul 2003
    Location
    London
    Posts
    4,138
    Thanks
    119
    Thanked
    100 times in 82 posts
    • streetster's system
      • Motherboard:
      • Asus P7P55D-E
      • CPU:
      • Intel i5 750 2.67 @ 4.0Ghz
      • Memory:
      • 4GB Corsair XMS DDR3
      • Storage:
      • 2x1TB Drives [RAID0]
      • Graphics card(s):
      • 2xSapphire HD 4870 512MB CrossFireX
      • PSU:
      • Corsair HX520W
      • Case:
      • Coolermaster Black Widow
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • DELL U2311
      • Internet:
      • Virgin 50Mb

    Re: Javascript Help

    Some sort of onclick event? have a read of this...

    For the second part, does this have to be (almost) purely javascript? why not create a form instead and you can pass a (hidden) value and make sure not to start with that question next time?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. javascript popup
    By hatsumi in forum Software
    Replies: 0
    Last Post: 28-12-2007, 01:17 AM
  2. Javascript help???
    By MagicFreebiesUK in forum Help! Quick Relief From Tech Headaches
    Replies: 0
    Last Post: 21-03-2007, 03:07 PM
  3. Replies: 6
    Last Post: 22-11-2006, 02:58 PM
  4. Replies: 2
    Last Post: 06-11-2006, 12:05 PM
  5. javascript not displaying in firefox
    By ZigZag in forum Software
    Replies: 3
    Last Post: 11-09-2005, 12:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •