JavaScript bra size calculator

One of the more mesmerizing websites I’ve worked on recently was for a lingerie boutique in the UK. Aside from the unenviable task of having to look at pictures of women in lingerie all day, I was also forced (forced!) to write a bra size calculator.

The theory behind bra size calculation is arcane and somewhat magical. Understanding of it does not come easily to man nor beast, so it is lucky that I, falling cleanly into neither category, have passed through pain and torment to save you the trouble.

Check it out.

Pleasing, no? The code looks like this, and can be found here:

var BraCalculator = {
  
  /**
   * The string to be returned when the result could not be calculated.
   */
  unknownString: "Unknown",
  
  cupSizes: ["A", "B", "C", "D", "DD", "E", "EE", "F", "FF", "G", "GG", "H", "HH", 
             "J", "JJ", "K", "KK", "L", "LL", "M", "MM", "N", "NN"],
  
  /**
   * Returns the correct bra size for given under bust and over bust measurements
   * @param {Number} underBust The measurement taken under the bust (in inches)
   * @param {Number} overBust The measurement taken over the bust (in inches)
   * @return {String} The correct bra size for the given measurements (e.g. 32C, 40DD, etc)
   */
  calculateSize: function(underBust, overBust) {
    var bandSize = this.calculateBandSize(underBust);
    var cupSize  = this.calculateCupSize(bandSize, overBust);
    
    if (bandSize && cupSize) {
      return bandSize + cupSize;
    } else {
      return this.unknownString;
    };
  },
  
  /**
   * Calculates the correct band size for a given under bust measurement
   * @param {Number} underBust The measurement under the bust
   * @return {Number} The correct band size
   */
  calculateBandSize: function(underBust) {
    var underBust = parseInt(underBust, 10);
    return underBust + (underBust % 2) + 2;
  },
  
  /**
   * Calculates the Cup size required given the band size and the over bust measurement
   * @param {Number} bandSize The measured band size (should be an even number)
   * @param {Number} overBust The measurement taken over the bust
   * @return {String} The appropriate alphabetical cup size
   */
  calculateCupSize: function(bandSize, overBust) {
    var bandSize = parseInt(bandSize, 10);
    var overBust = parseInt(overBust, 10);
    var diff     = overBust - bandSize;
    
    var result   = this.cupSizes[diff][/diff];
    
    //return false if we couldn't lookup a cup size
    return result ? result : false;
  }
};

And to apply it to your own pages, use something a bit like this:

jQuery(document).ready(function(){
  //add listeners to band and cup measurement text boxes
  jQuery('#back').keyup(Honeys.updateBraSizeCalculation);
  jQuery('#cup').keyup(Honeys.updateBraSizeCalculation);
});

var Honeys = {
  updateBraSizeCalculation: function() {
    var back = jQuery('#back')[0].value;
    var cup  = jQuery('#cup')[0].value;
    
    if (back.length > 0 && cup.length > 0) {
      jQuery('#fit')[0].value = BraCalculator.calculateSize(back, cup);
    };
  }
};

Now we’re talking UK sizes here, so exercise extreme caution! It should be trivial to adapt to your country with our lovely conversion charts.

Don’t pretend you’re not going to play with it. You know you are. Like, right now.

9 Responses to JavaScript bra size calculator

  1. FlyboyArt says:

    It’s a tough job but someone has to do it. I assume you had some ‘field work’ to make sure the sizes are accurately represented?;=}

  2. gf says:

    The only thing better than having to code it would have been doing Q/A on it… uh… this doesn’t look like it’s matching the inputs. I’ll need to take new measurements and confirm the output….

  3. Anonymous says:

    *rolls eyes* This is the size chart that keeps saying I’m a 30D. I wear US bras, true, but the size conversion says that 32A in the US is the same as a 32A in Britain. 32A=/=30D. Trust me on this; I have a small bust, and there is no way that a D-cup of any band size is going to fit me.

  4. Edward Spencer says:

    Hi Anonymous. I did say Bra Theory was somewhat arcane! The ladies I made this for gave me a chart to go off, to which I fitted a fairly simple function. This function does hit all of their data points correctly – make of that what you will…One thing they did say though is that cup size names vary from manufacturer to manufacturer – not just country to country. This surprised me somewhat as a 30D from one company could be pretty close to a 32A from another (as an example only… I’m guessing at the actual measurements there but the concept is the important thing).You obviously know the subject much better than I do – I just did what I was told!

  5. Anonymous says:

    I must say yours is one of the most accurate bra size calculators I've seen… in some other calculators I got some clearly ridiculous outcomes.

  6. Anonymous says:

    Hello, Edward. This is the first anonymous, the one that got the result that just seemed impossible. It turns out that a 30 band actually does fit me pretty well, but in the only brand I've ever been able to find it in, the B cup was a little loose and I ended up buying the size A one which fit better. I'm not blaming you for making the program fit the chart you were given, but the brand(s) used on that chart were definitely designed and sized far different than any bra I've ever been able to find in a 30 band! Bra sizing really is crazy…

  7. Ed Spencer says:

    Dear Anonymous,

    I am sorry to hear that my calculator decrees your chest to be impossibly proportioned – clearly in this matter you must be given the benefit of the doubt. The code has been suitably admonished and is currently hiding, red-faced and embarrassed in a corner.

    Your namesake before you mentioned just recently that she (I presume) found it most accurate – the intricacies of human anatomy continue to inspire and frustrate. I can only hope that your search for acceptable garmentry bears fruit, and wish you luck in all such endeavours.

  8. Amber C says:

    Dear Ed:
    There’s one more thing…there does exist a cup size “AA”…for those ‘slightly smaller’ women, that should have been included in this calculator!!

  9. Latrice says:

    We are a group of volunteers and starting a new scheme inn ourr community.
    Your website provided uss with valuable info to work on.
    You’ve done a formidable job aand oour entire community wjll
    bbe grateful to you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: