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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Weight converter</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  <style>
  body{
    margin-top: 70px;
    background: #333;
    color:#fff;

  }

  </style>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="col-md-6 offset-md-3">
        <h1 class="display-4 text-center  mb-3">Weight Converter</h1>
        <p class="pull-left">select weight type:</p>
        <button type="button" class="btn btn-danger mb-1" id="lbSelector">lb</button>
        <button type="button" class="btn btn-danger mb-1 "id="grSelector">gr</button>
        <button type="button" class="btn btn-danger mb-1"id="kgSelector">kg</button>
        <button type="button" class="btn btn-danger mb-1"id="ozSelector">oz</button>
        <form>
          <div class="form-group">
            <input
            id="input"
            type="number"
            class="form-control form-control-lg"
            placeholder="Enter weight..">
          </div>
        </form>
        <div id="output">
          <div class="card card-primary mb-2">
            <div class="card-block">
              <h4 id="blueOutputText"></h4>
              <div id="blueOutput"></div>
            </div>
          </div>
          <div class="card card-success  mb-2">
            <div class="card-block">
              <h4 id="greenOutputText"></h4>
              <div id="greenOutput"></div>
            </div>
          </div>
          <div class="card card-danger  mb-2">
            <div class="card-block">
              <h4 id="redOutputText"></h4>
              <div id="redOutput"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
<script>
document.getElementById("output").style.visibility = 'hidden';
document.getElementById("input").style.visibility = 'hidden';
//POUNDS TO OTHER
          //if click on lb remove red from lb and add green to lb others red
  document.getElementById("lbSelector").onclick = function() {
  document.getElementById("lbSelector").classList.remove('btn-danger');
  document.getElementById("lbSelector").classList.add('btn-success');
  document.getElementById("kgSelector").classList.add('btn-danger');
  document.getElementById("ozSelector").classList.add('btn-danger');
  document.getElementById("grSelector").classList.add('btn-danger');
          //input field get visible
  document.getElementById("input").style.visibility = 'visible';
          //get input numbers dynamically set var enteredWeight
  document.getElementById("input").addEventListener('input', function(e){
  document.getElementById("output").style.visibility = 'visible';
   let enteredWeight = e.target.value;
         //change names on displays and add adequat formulas to display right results
   document.getElementById('blueOutput').innerHTML = enteredWeight/0.0022046;
   document.getElementById('blueOutputText').innerHTML = "Grams:";
   document.getElementById('greenOutput').innerHTML = enteredWeight/2.2046;
   document.getElementById('greenOutputText').innerHTML = "Kilograms:";
   document.getElementById('redOutput').innerHTML = enteredWeight*16;
   document.getElementById('redOutputText').innerHTML = "Ounces:";
  }
);

}
//GRAMS TO OTHER
        //if click on gr remove red from gr and add green to gr others red
  document.getElementById("grSelector").onclick = function() {
  document.getElementById("grSelector").classList.remove('btn-danger');
  document.getElementById("grSelector").classList.add('btn-success');
  document.getElementById("kgSelector").classList.add('btn-danger');
  document.getElementById("ozSelector").classList.add('btn-danger');
  document.getElementById("lbSelector").classList.add('btn-danger');
        //input field get visible
  document.getElementById("input").style.visibility = 'visible';
        //get input numbers dynamically set var enteredWeight
  document.getElementById("input").addEventListener('input', function(e){
  document.getElementById("output").style.visibility = 'visible';
   let enteredWeight = e.target.value;
        //change names on displays and add adequat formulas to display right results
   document.getElementById('blueOutput').innerHTML = enteredWeight*0.0022046;
   document.getElementById('blueOutputText').innerHTML = "Pounds:";
   document.getElementById('greenOutput').innerHTML = enteredWeight/1000;
   document.getElementById('greenOutputText').innerHTML = "Kilograms:";
   document.getElementById('redOutput').innerHTML = enteredWeight*0.03527396;
   document.getElementById('redOutputText').innerHTML = "Ounces:";
  }
);
}
//KILOGRAMS TO OTHER
        //if click on Kg remove red from kg and add green to Kg others red
  document.getElementById("kgSelector").onclick = function() {
  document.getElementById("kgSelector").classList.remove('btn-danger');
  document.getElementById("kgSelector").classList.add('btn-success');
  document.getElementById("grSelector").classList.add('btn-danger');
  document.getElementById("ozSelector").classList.add('btn-danger');
  document.getElementById("lbSelector").classList.add('btn-danger');
        //input field get visible
  document.getElementById("input").style.visibility = 'visible';
        //get input numbers dynamically set var enteredWeight
  document.getElementById("input").addEventListener('input', function(e){
  document.getElementById("output").style.visibility = 'visible';
   let enteredWeight = e.target.value;
         //change names on displays and add adequat formulas to display right results
   document.getElementById('blueOutput').innerHTML = enteredWeight*2.20462262;
   document.getElementById('blueOutputText').innerHTML = "Pounds:";
   document.getElementById('greenOutput').innerHTML = enteredWeight*1000;
   document.getElementById('greenOutputText').innerHTML = "Grams:";
   document.getElementById('redOutput').innerHTML = enteredWeight*35.2739619;
   document.getElementById('redOutputText').innerHTML = "Ounces:";

  }
);
}
//OUNCES TO OTHER
        //if click on oz remove red from oz and add green to oz others red
  document.getElementById("ozSelector").onclick = function() {
  document.getElementById("ozSelector").classList.remove('btn-danger');
  document.getElementById("ozSelector").classList.add('btn-success');
  document.getElementById("grSelector").classList.add('btn-danger');
  document.getElementById("kgSelector").classList.add('btn-danger');
  document.getElementById("lbSelector").classList.add('btn-danger');
        //input field get visible
  document.getElementById("input").style.visibility = 'visible';
         //get input numbers dynamically set var enteredWeight
  document.getElementById("input").addEventListener('input', function(e){
  document.getElementById("output").style.visibility = 'visible';
   let enteredWeight = e.target.value;
         //change names on displays and add adequat formulas to display right results
   document.getElementById('blueOutput').innerHTML = enteredWeight/16;
   document.getElementById('blueOutputText').innerHTML = "Pounds:";
   document.getElementById('greenOutput').innerHTML = enteredWeight*28.3495231;
   document.getElementById('greenOutputText').innerHTML = "Grams:";
   document.getElementById('redOutput').innerHTML = enteredWeight/35.2739619;
   document.getElementById('redOutputText').innerHTML = "Kilograms:";
  }
);

}
//how to make this simple? using functions? How to make when change selested type change displays titles and results?
</script>

</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console