Grow your CSS skills. Land your dream job.

Returning every third odd number within a user specified range

  • # April 9, 2013 at 1:27 am

    All I am trying to do is simply return every third odd number within a specified range.

    This one is a bit weird for me, I tried a few different things but nothing even worth posting as my attempts yielded no results close to what i was looking for, I have a feeling it is out of the scope of my current capabilities, any help would be GREATLY appreciated. Thanks in advance.

    # April 9, 2013 at 1:31 am

    are the numbers consecutive? like 1-100 or 323-555?

    # April 9, 2013 at 1:38 am

    Consecutive, Starting at 1….What i am going to do since it is for my personal use is make an html form with 2 text boxes for the range…the closest thing i have of the basic functionality is this, i just am not sure where to go from there…and i don;t think it is looping correctly i still have to check on that….like i said, i know crap about javascript…i can do every other with this method, not every third though…

    perhaps using splice or push would be a better option?

    var arr = [1,3,5,7,9,11,13,15,17,19,21,23,25];
    for(var i = 1; i < arr.length; i+=2){
    console.log(i);
    }

    # April 9, 2013 at 1:48 am

    get the value of the end of the range the second input and change arr.length with that value, no need to store all the odd numbers to an array

    # April 9, 2013 at 1:55 am

    I am going to expand on this so using an array will make it easier for me to work with when i get that far…

    Here is my thought on using the splice idea, I think this one works just fine actually for my purpose:

    var arr = [1,3,5,7,9,11,13,15,17,19,21,23,25];

    for(var i = 0; i < arr.length; i++) {
    arr.splice(i+1,2);
    }

    console.log(arr);

    # April 9, 2013 at 2:21 am

    you dont know how big the range will be so storing the array before that its wrong , have a look at this code
    http://codepen.io/anon/pen/Gtflb also checks if the input is a number larger than zero

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".