Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. var obj {};
  2. var storedObject;
  3. var randomResponse1 = pickRand1(obj);
  4. var randomResponse2 = pickRand1(obj);
  5.  
  6. //first visit to server
  7. if (event.reply == "true") {
  8. obj.1 = 'one';
  9. obj = storedObject;
  10. }
  11.  
  12. //second visit to server
  13. if (event.reply == "true") {
  14. obj.2 = 'two';
  15. obj = storedObject;
  16. }
  17.  
  18.  
  19. //third visit to server
  20. if (event.reply == "true") {
  21. obj.3 = 'three';
  22. obj = storedObject;
  23. }
  24.  
  25.  
  26. //fourth visit to server
  27. if (event.reply == "true") {
  28. obj.4 = 'four';
  29. obj = storedObject;
  30. }
  31.  
  32.  
  33. //final visit to server
  34. if (event.reply == "true") {
  35. alert(randomResponse1); //it only seems to grab last value
  36. alert(randomResponse2); //also, does this have a chance of
  37. //being the same random result?
  38. }
  39.  
  40.  
  41. function pickRand1(obj) {
  42. var result;
  43. var count = 0;
  44. for (var prop in obj)
  45. if (Math.random() < 1/++count)
  46. result = obj[prop];
  47. return result;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement