Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    Regular Coder
    Join Date
    Mar 2006
    Posts
    725
    Thanks
    35
    Thanked 132 Times in 123 Posts
    Code:
    function pickaNumber(){
    	var pick, index, nums;
    	if(!document.cookie || !/\d/.test(document.cookie)){
    		nums= [];
    		for(var i= 0;i<80;i++)nums[i]= i+1;
    		document.cookie= 'numbers='+nums.join(',');
    	}
    	nums= document.cookie.split('=')[1].match(/(\d+)/g);
    	index= Math.floor(Math.random()*nums.length);
    	pick= nums.splice(index, 1);
    	document.cookie= 'numbers='+nums.join(',');
    	return pick[0];
    }
    //alert(pickaNumber())
    Last edited by mrhoo; 04-21-2013 at 06:30 AM. Reason: formatting

  2. #17
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    216
    Thanks
    0
    Thanked 29 Times in 27 Posts
    Bravo mrhoo ! You understand what it means to take one of the remaining numbers !

  3. #18
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by 007julien View Post
    Bravo mrhoo ! You understand what it means to take one of the remaining numbers !
    A poor solution, IMO, which relies on cookies which the user can easily erase.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  4. #19
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    216
    Thanks
    0
    Thanked 29 Times in 27 Posts
    A poor response, which does not address the real issue !

  5. #20
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by 007julien View Post
    A poor response, which does not address the real issue !
    And the real issue is what?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  6. #21
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    since there are likely going to be fewer than 80 views, and in fact likely only a few, it would be more efficient to track the numbers used instead of unused.

    that said, it looks like you kids are having too much fun for me to interject, and we don't need to take this script to the moon, just around the block...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  7. #22
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by Old Pedant View Post
    But I think you all *MAY* have missed an important requirement that MJared made.


    To me, that means if the user goes to another web page and then comes back to this same page, without closing the browser, then he/she should continue getting numbers from the same set of 1 through 80. Certainly that's the implication of "browser session" when referring to (for example) server side session variables in PHP/JSP/ASP.

    And that means that the array needs to be stored in a session cookie.
    I think that the OP is not using the right terminology. He probably means per page visit. I don't think that he really needs to store the selected numbers in a cookie.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  8. #23
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,459
    Thanks
    0
    Thanked 632 Times in 622 Posts
    Quote Originally Posted by Philip M View Post
    He probably means per page visit.
    Since the OP specified that each number is followed by a submit (and that takes the person to a new page) there will be one page visit per number so a session MUST involve multiple pages.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  9. #24
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    ahh, arguing over different assumptions based on unclear input, the cornerstone of a good forum thread.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  10. #25
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    "The great thing about a boolean is that even if you're wrong, you're only off by a bit."

  11. #26
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,459
    Thanks
    0
    Thanked 632 Times in 622 Posts
    Quote Originally Posted by rnd me View Post
    ahh, arguing over different assumptions based on unclear input
    Presumably the OP already got the answer they think they wanted or they'd have clarified what was meant by now.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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