treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Tryint to create the index of a constructor

  • function Category(year, min, max) {
    this.count = year;
    this.min = min;
    this.max = max;
    }
    var mazda = new Category(1995, 0, 12),
    honda = new Category(1998, 0, 14);


    What'd i'd like is to be able to call an index of Category. So Category[0] could yield (1995,0,12). Any ideas?
  • I think I'm totally lost
    But is this what you mean?
    http://jsfiddle.net/c8K7D/
  • Thanks so much for your speedy reply. I think that might help, but I should have explained in more detail. I'm trying to make this bit of code more flexible. I've set up a div with two buttons and a span holding counter.
    <div id='kid'>
    <button>Up</button>
    <span></span>
    <button>Down</button>
    </div>
    What'd I'd like to do is have the javascript flexible enough, that no matter how many button counter structures one add, the javascript could identify which button was clicked and the count up or down and update the span.

    *Oh and so that each button/counter structure could have it's own set of min/max values where one the value is reached the button is disabled

    You can see how I've set it up currently at: http://jsfiddle.net/mhumeSF/vJrpE/17/