Friday, November 28th, 2008

JavaScript Bra Size Calculator

Category: Examples, JavaScript, Showcase

Now this could only fly on a Friday ;)

Ed Spencer has coded up a bra size calculator in JavaScript:

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.

After hours of testing he came up with the BraCalculator:


  1. var BraCalculator = {
  3.   /**
  4.    * The string to be returned when the result could not be calculated.  Overwrite to change this
  5.    */
  6.   unknownString: "Unknown",
  8.   cupSizes: ["A", "B", "C", "D", "DD", "E", "EE", "F", "FF", "G", "GG", "H", "HH",
  9.              "J", "JJ", "K", "KK", "L", "LL", "M", "MM", "N", "NN"],
  11.   /**
  12.    * Returns the correct bra size for given under bust and over bust measurements
  13.    * @param {Number} underBust The measurement taken under the bust (in inches)
  14.    * @param {Number} overBust The measurement taken over the bust (in inches)
  15.    * @return {String} The correct bra size for the given measurements (e.g. 32C, 40DD, etc)
  16.    */
  17.   calculateSize: function(underBust, overBust) {
  18.     var bandSize = this.calculateBandSize(underBust);
  19.     var cupSize  = this.calculateCupSize(bandSize, overBust);
  21.     if (bandSize && cupSize) {
  22.       return bandSize + cupSize;
  23.     } else {
  24.       return this.unknownString;
  25.     };
  26.   },
  28.   /**
  29.    * Calculates the correct band size for a given under bust measurement
  30.    * @param {Number} underBust The measurement under the bust
  31.    * @return {Number} The correct band size
  32.    */
  33.   calculateBandSize: function(underBust) {
  34.     var underBust = parseInt(underBust, 10);
  35.     return underBust + (underBust % 2) + 2;
  36.   },
  38.   /**
  39.    * Calculates the Cup size required given the band size and the over bust measurement
  40.    * @param {Number} bandSize The measured band size (should be an even number)
  41.    * @param {Number} overBust The measurement taken over the bust
  42.    * @return {String} The appropriate alphabetical cup size
  43.    */
  44.   calculateCupSize: function(bandSize, overBust) {
  45.     var bandSize = parseInt(bandSize, 10);
  46.     var overBust = parseInt(overBust, 10);
  47.     var diff     = overBust - bandSize;
  49.     var result   = this.cupSizes[diff];
  51.     //return false if we couldn't lookup a cup size
  52.     return result ? result : false;
  53.   }
  54. };

Check it out in action

Posted by Dion Almaer at 1:33 pm

3.3 rating from 41 votes


Comments feed TrackBack URI

Just tried it on the lady. She said the results were accurate.

Comment by ded — November 28, 2008

Uhm… we are left a bit puzzled, first we had to change centimeters to inches then I had to figure out if the results are uk to get a proper results from the charts…
And uhm… my lady had a minimizer on while we measured but still…
Euro 80E is not (what she measures) Euro 95F (thats right, 42E in the uk :)

By the way, 42E (or in Euro 95F) is very difficult to come by, anyone knows a good store?

Comment by Marc — November 28, 2008

Sexiest JavaScript yet.

Comment by Nosredna — November 28, 2008

I usually appreciate the ajaxian posts because they contain tips or scripts that i can apply on my projects. Posts usually highlight projects which have general applicability or demonstrate a principal which can be generally applied.

This post is a waste of time. Even for a friday.

Comment by ndluthier — November 28, 2008

Since I’ve completely given up on getting Dion and Co to actually write something specific about my things I posts here a link to my latest innovation; – Stacked and Open Source implementation of…
Check out the code at;
Yes this is kind of spam, but since I’m on .Net I cannot get any attention even if I bend time and matter, so therefore I think it’s justified…
Feedback is appreciated :)

Comment by ThomasHansen — November 28, 2008

haha quality! I knew JavaScript was sexy but dammmmn lol

Comment by aaronmcadam — November 28, 2008

Brilliant, I was in need of a good laugh. Even managed to learn something. Thank you.

Comment by paulhan — November 28, 2008

I can’t believe this made it on here… :p

Thanks for the compliments, and sorry you didn’t like it ndluthier. Must be a slow news day I guess!

Marc, I put a note on the article that this is principally aimed at UK ladies, but that it should be pretty easy to adapt to other countries (there’s a link to some conversion charts too). Hope that helps

Comment by EdSpencer — November 28, 2008

Last line in calculateCupSize can be written :

return this.cupSizes || false;

Comment by SamoriGorse — November 30, 2008

I think the fact that Dion puts this kind of stuff on here is awesome. It keeps a sense of humor in our every day lives.

Comment by ded — December 1, 2008

Thanks Dustin :)

By the way I really enjoyed your Pro JavaScript Design Patterns book – the first 5 chapters taught me more about writing good JS than I had picked up in the whole previous year. I recommend it to everyone who asks me how to learn JavaScript.

Comment by EdSpencer — December 1, 2008

Leave a comment

You must be logged in to post a comment.