Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /**
 * Common Olympic (2-inch center hole) plate denominations are 2.5, 5, 10, 25, 35, and 45 lbs,[12] with 1.25 and 100 pound discs less commonly seen.
 * https://www.hamptonfit.com/wp-content/uploads/2014/04/PBP.jpg
 * https://www.ironcompany.com/media/catalog/product/cache/6e8e24cc73e2eff11526e72b5f24c033/u/p/upt-Urethane-Encased-Barbell-Plates-xlg.jpg
 */

const PLATE_2_5 = 2.5;
const PLATE_5 = 5;
const PLATE_10 = 10;
const PLATE_25 = 25;
const PLATE_35 = 35;
const PLATE_45 = 45;
const BARBELL_WEIGHT = 45;

function getNeededPlatesForWeight(weight) {
  console.log('weight is: ' + weight);
  let neededPlates = {
      [PLATE_2_5]: 0,
      [PLATE_5]: 0,
      [PLATE_10]: 0,
      [PLATE_25]: 0,
      [PLATE_35]: 0,
      [PLATE_45]: 0
  };
  
  if (weight <= BARBELL_WEIGHT) {
    console.log('lifting the empty bar is enough for that weight');
    return [];
  }
  
  let weightPerSide = (weight - BARBELL_WEIGHT) / 2;

  if (weightPerSide % PLATE_2_5 !== 0) {
    console.log('The requested weight can\'t be exactly loaded with the standard weight plates');
    return [];
}
  
  while (weightPerSide >= PLATE_2_5) {

    if (weightPerSide >= PLATE_45) {
        neededPlates[PLATE_45] += 1;
        weightPerSide -= PLATE_45;
    } else if (weightPerSide >= PLATE_35) {
        neededPlates[PLATE_35] += 1;
        weightPerSide -= PLATE_35;
    } else if (weightPerSide >= PLATE_25) {
        neededPlates[PLATE_25] += 1;
        weightPerSide -= PLATE_25;
    } else if (weightPerSide >= PLATE_10) {
        neededPlates[PLATE_10] += 1;
        weightPerSide -= PLATE_10;
    } else if (weightPerSide >= PLATE_5) {
        neededPlates[PLATE_5] += 1;
        weightPerSide -= PLATE_5;
    } else if (weightPerSide >= PLATE_2_5) {
        neededPlates[PLATE_2_5] += 1;
        weightPerSide -= PLATE_2_5;
    }
  }

  console.log('Weight sucessfully loaded');
  return neededPlates;
}

// Test less than minimum weight
console.log(getNeededPlatesForWeight(-10));
console.log(getNeededPlatesForWeight(0));
console.log(getNeededPlatesForWeight(40));
console.log(getNeededPlatesForWeight(45));

// Test not possible weight
console.log(getNeededPlatesForWeight(47.5));

// Test valid weights
console.log(getNeededPlatesForWeight(100));
console.log(getNeededPlatesForWeight(120));
console.log(getNeededPlatesForWeight(150));
console.log(getNeededPlatesForWeight(200));
              
            
!
999px

Console