Skip to content

Instantly share code, notes, and snippets.

@amandasaffer
Created September 18, 2016 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amandasaffer/003b2ba463443a14f0778286a4440e9f to your computer and use it in GitHub Desktop.
Save amandasaffer/003b2ba463443a14f0778286a4440e9f to your computer and use it in GitHub Desktop.
$(".calculate").click(function() {
event.preventDefault();
//grab values
var chestSize = parseInt($('.chestSize').val());
var waistSize = parseInt($('.waistSize').val());
var height = $(".height").children(":selected").attr("class");
//correct chest and waist values (+1) if odd
function oddCheck(x) {
if (x % 2 == 0) {
return true;
} else {
return false;
}
}
if (oddCheck(chestSize) === false) {
chestSize += 1;
}
if (oddCheck(waistSize) === false) {
waistSize += 1;
}
// calculate
var heightInit = height.charAt(0).toUpperCase();
var measurement;
if (chestSize - waistSize > 7) {
measurement = chestSize;
} else {
measurement = chestSize + 2;
}
var size = measurement + " " + heightInit + height.slice(1) + " (" + measurement + heightInit + ")";
//post
$('.result').html('');
$('.result').html(size);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment