JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=VT323' rel='stylesheet'>
</head>
<body>
<H1>BMI CALCULATOR</H1>
<div id="scale_main">
<div id="scale_display">
<h2 id="range" class="neutral">Enter Measurements</h2>
<h3 id="bmi" >--.--</h3>
<div id="needle">
</div>
<div id="needle_bottom">
</div>
</div>
<div class="measurement" id="height">
<h4>Height</h4>
<input class="input" type="text" id="height_input" name="height" required></input>
<span class="unit">Inches</span>
</div>
<div class="measurement" id="weight">
<h4>Weight</h4>
<input class="input" type="text" id="weight_input" name="weight" required></input>
<span class="unit">Pounds</span>
</div>
<div>
<button id="calculate" onclick="calculate(document.getElementById('height_input').value, document.getElementById('weight_input').value)">CALCULATE</button>
<button id="clear" onclick="clear_calculator()">CLEAR</button>
</div>
</div>
</body>
</html>
body{
background-color: #B1FAFF;
}
h1{
text-align: center;
font-family: sans-serif;
color: #0182D8;
font-size: 36px;
margin-top: 80px;
}
h2{
text-align: center;
margin-bottom: 5px;
font-family: sans-serif;
font-size: 20px;
}
h3{
text-align: center;
margin-top: 0px;
font-family: "VT323";
font-size: 32px;
color: #FFFFFF;
margin-bottom: 5px;
}
h4{
font-family: sans-serif;
margin-bottom: 5px;
margin-top: 85px;
font-size: 20px;
color: #0182D8;
}
#scale_main{
background-color: #FFFFFF;
width: 600px;
min-height: 650px;
margin: 0 auto;
margin-top: 20px;
border-radius: 20px;
box-shadow: -1px 3px 15px #888888;
}
#scale_display{
background-color: #DEE0E5;
width: 60%;
height: 140px;
margin-left: 20%;
margin-top: 50px;
border-radius: 100px 100px 0 0;
float: left;
box-shadow: 0px -1px 2px #888888;
}
#needle{
background-color: #E22A2A;
width: 3px;
height: 47px;
margin-left: 50%;
box-shadow: 0px 3px 15px #888888;
}
#needle_bottom{
background-color: #E22A2A;
width: 20px;
height: 12px;
margin-left: 47.5%;
border-radius: 100px 100px 0px 0px;
box-shadow: 0px -1px 7px #888888;
}
.measurement{
width: 40%;
float: left;
margin-left: 10%;
}
.input{
width: 45%;
font-size: 24px;
vertical-align: bottom;
border-color: #DEE0E5;
border-style: solid;
font-family: sans-serif;
}
.unit{
font-family: sans-serif;
font-weight: 700;
font-size: 20px;
}
#calculate{
margin-left: 35%;
margin-top: 100px;
padding: 4px 40px;
border-radius: 7px;
font-size: 20px;
box-shadow: 0px 0px;
border-style: none;
color: #FFFFFF;
background-color: #16BE5F;
}
#calculate:hover{
cursor: pointer;
}
#clear{
margin-left: 35%;
margin-top: 15px;
padding: 4px 65px;
border-radius: 7px;
font-size: 20px;
box-shadow: 0px 0px;
border-style: none;
color: #FFFFFF;
background-color: #E22A2A;
}
#clear:hover{
cursor: pointer;
}
.neutral{
color: #000000;
}
.good{
color: #16BE5F;
}
.bad{
color: #E22A2A;
}
function calculate(height, weight) {
weight = parseInt(weight);
height = parseInt(height);
console.log("Height", height);
console.log("Weight", weight);
weight = weight * 703;
height = height*height;
var bmi = weight/height;
console.log("BMI: ", bmi);
document.getElementById('bmi').innerHTML = bmi.toPrecision(3);
if(bmi < 18.5)
{
document.getElementById('range').innerHTML = "Underweight";
document.getElementById('range').classList.remove("neutral");
document.getElementById('range').classList.remove("good"); document.getElementById('range').classList.add("bad");
}
if(bmi >= 18.5 && bmi < 25)
{
document.getElementById('range').innerHTML = "Normal";
document.getElementById('range').classList.remove("neutral");
document.getElementById('range').classList.remove("bad"); document.getElementById('range').classList.add("good");
}
if(bmi >= 25 && bmi < 30)
{
document.getElementById('range').innerHTML = "Overweight";
document.getElementById('range').classList.remove("neutral");
document.getElementById('range').classList.remove("good"); document.getElementById('range').classList.add("bad");
}
if(bmi > 30)
{
document.getElementById('range').innerHTML = "Obese";
document.getElementById('range').classList.remove("neutral");
document.getElementById('range').classList.remove("good"); document.getElementById('range').classList.add("bad");
}
};
function clear_calculator(){
console.log("Clear");
document.getElementById('range').classList.remove("bad");
document.getElementById('range').classList.remove("good");
document.getElementById('range').classList.add("neutral");
document.getElementById('range').innerHTML = "Enter Measurements";
document.getElementById('bmi').innerHTML = "--.--";
document.getElementById('height_input').value="";
document.getElementById('weight_input').value="";
document.getElementById('height_input').focus();
};
Also see: Tab Triggers