Results 1 to 11 of 11

Thread: random questions w/o repetition

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2012
    Posts
    8
    Qt products
    Qt3 Qt5
    Platforms
    Windows Symbian S60

    Default Re: random questions w/o repetition

    so i have to do it again in array format... oh my
    now i know what OP is...

    here the complete js code

    Qt Code:
    1. function riddles() {
    2. var db = openDatabaseSync ("riddleDB", "1.0", "riddle database", 10000)
    3. var rs
    4.  
    5. db.transaction(
    6. function(tx) {
    7. tx.executeSql ('CREATE TABLE IF NOT EXISTS riddle(riddle_id NUMBER,' +
    8. 'riddle_question VARCHAR2, riddle_answer VARCHAR2, score NUMBER)');
    9.  
    10. rs = tx.executeSql('Select riddle_id from riddle');
    11. if (rs.rows.length == 0) {
    12. tx.executeSql('INSERT INTO riddle VALUES(1, "What goes up but never goes down?", "Age", 10, "music.mp3")');
    13. tx.executeSql('INSERT INTO riddle VALUES(2, "What pet is always on the floor?", "Carpet", 10, "music.mp3")');
    14. tx.executeSql('INSERT INTO riddle VALUES(3, "The more you take the more you leave behind", "Footsteps", 10, "music.mp3")');
    15. tx.executeSql('INSERT INTO riddle VALUES(4, "What is the only room from which no one can enter or leave?", "Mushroom", 10, "music.mp3")');
    16. tx.executeSql('INSERT INTO riddle VALUES(5, "The person who makes it, sells it. The person who buys it never uses it and the person who uses it doesnt know they are. What is it?", "Coffin", 10, "music.mp3")');
    17. tx.executeSql('INSERT INTO riddle VALUES(6, "What goes round the house and in the house but never touches the house?", "Sun", 10, "music.mp3")');
    18. tx.executeSql('INSERT INTO riddle VALUES(7, "What is in seasons, seconds, centuries and minutes but not in decades, years or Days?", "N", 10, "music.mp3")');
    19. tx.executeSql('INSERT INTO riddle VALUES(8, "The more you have of it, the less you see. What is it?", "Darkness", 10, "music.mp3")');
    20. tx.executeSql('INSERT INTO riddle VALUES(9, "What is black when you get it, red when you use it, and white when you are all through with it?", "Charcoal", 10, "music.mp3")');
    21. tx.executeSql('INSERT INTO riddle VALUES(10, "My life can be measured in hours, I serve by being devoured.Thin, I am quick Fat, I am slow Wind is my foe.", "Fire", 10, "music.mp3")');
    22. tx.executeSql('INSERT INTO riddle VALUES(11, "I build up castles.I tear down mountains.I make some men blind,I help others to see.What am I?", "Sand", 10, "music.mp3")');
    23. tx.executeSql('INSERT INTO riddle VALUES(12, "What is it that after you take away the whole, some still remains?", "Wholesome", 10, "music.mp3")');
    24. tx.executeSql('INSERT INTO riddle VALUES(13, "I can be long, or I can be short. I can be grown, and I can be bought. I can be painted, or left bare. I can be round, or square. What am I?", "Fingernails", 10, "music.mp3")');
    25. tx.executeSql('INSERT INTO riddle VALUES(14,"What has a neck and no head, two arms but no hands?", "Shirt", 10, "music.mp3")');
    26. tx.executeSql('INSERT INTO riddle VALUES(15, "Remove six letters from this sequence to reveal a familiar English word. BSAINXLEATNTEARS", "Banana", 10, "music.mp3")');
    27. tx.executeSql('INSERT INTO riddle VALUES(16, "I am white, I am round, but not always around. Sometimes you see me, sometimes you dont. What am I?", "Moon", 10, "music.mp3")');
    28. tx.executeSql('INSERT INTO riddle VALUES(17, "I have an end but no beginning, a home but no family, a space without room. I never speak but there is no word I cannot make. What am I?", "Keybord", 10, "music.mp3")');
    29. tx.executeSql('INSERT INTO riddle VALUES(18, "I am an insect, & the first half of my name reveals another insect. Some famous musicians had a name similar to mine. What am I? ", "Beetle", 10, "music.mp3")');
    30. tx.executeSql('INSERT INTO riddle VALUES(19, "It is greater than God and more evil than the devil. The poor have it, the rich need it and if you eat it youll die. What is it?", "Nothing", 10, "music.mp3")');
    31. tx.executeSql('INSERT INTO riddle VALUES(20, "I never was, am always to be. No one ever saw me, nor ever will. And yet I am the confidence of all, To live and breathe on this terrestrial ball. What am I?", "Tomorrow", 10, "music.mp3")');
    32. tx.executeSql('INSERT INTO riddle VALUES(21, "There was a green house. Inside the green house there was a white house. Inside the white house there was a red house. Inside the red house there were lots of babies. What is it?", "Watermelon", 10, "music.mp3")');
    33. tx.executeSql('INSERT INTO riddle VALUES(22, "If you can purchase 8 eggs for 26 cents, how many can you buy for a cent and a quarter?", "Eight", 10, "music.mp3")');
    34. tx.executeSql('INSERT INTO riddle VALUES(23, "If you look you cannot see me. And if you see me you cannot see anything else. I can make anything you want happen, but later everything goes back to normal. What am I?", "Imagination", 10, "music.mp3")');
    35. tx.executeSql('INSERT INTO riddle VALUES(24, "I have a head and tail but no body. What am I?", "Coin", 10, "music.mp3")');
    36. tx.executeSql('INSERT INTO riddle VALUES(25, "When you have me, you feel like sharing me. But, if you do share me, you dont have me. What am I?", "Secret", 10, "music.mp3")');
    37.  
    38. }
    39. })
    40. }
    41.  
    42.  
    43. //Riddle_Question
    44.  
    45. function riddles1() {
    46. var db = openDatabaseSync("riddleDB","1.0","riddle database", 10000)
    47. var rs
    48. var QCount
    49. //var ridCount
    50.  
    51. db.transaction(function(tx) {
    52. rs = tx.executeSql('SELECT * FROM riddle')
    53. })
    54.  
    55. //randomized riddle
    56. for ( var i = 1; i < (rs.rows.length - 1); i++) {
    57. var n = (Math.random() * (rs.rows.length))
    58. if (null != rs.rows.length) {
    59. QCount++;
    60. }
    61. }
    62.  
    63. hidden.text = rs.rows.item(n).riddle_id
    64. txtQuestion.text = rs.rows.item(n).riddle_question
    65. ridCount++
    66. answers.text = ""
    67. }
    68.  
    69. function score1() {
    70. var db = openDatabaseSync("riddleDB","1.0","riddle database", 10000)
    71. var rs
    72.  
    73. db.transaction(function(tx) {
    74. rs = tx.executeSql('SELECT * FROM riddle where riddle_id = "' + parseInt(hidden.text) + '"')
    75. })
    76.  
    77. if (answers.text == rs.rows.item(0).riddle_answer)
    78. ridScore = ridScore + 1
    79.  
    80. if ((answers.text != rs.rows.item(0).riddle_answer))
    81. riddlemaster.state = "wrong"
    82. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: random questions w/o repetition

    You don't have to use arrays if you use the second solution I suggested.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Random markers from nowhere.
    By Spitfire in forum Qwt
    Replies: 10
    Last Post: 3rd November 2011, 14:43
  2. random alphabets
    By hema in forum Newbie
    Replies: 3
    Last Post: 20th July 2011, 17:23
  3. Possible to get random value in QMultiHash/Map?
    By weevil in forum Qt Programming
    Replies: 2
    Last Post: 29th June 2010, 11:00
  4. Replies: 1
    Last Post: 7th April 2010, 16:26
  5. random
    By raphaelf in forum General Programming
    Replies: 9
    Last Post: 6th June 2007, 12:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.