Skip to main content

Control Your Weights using this Javascript App - Simple BMI Calculator

 


    Embark on a coding journey that will demystify the intricacies of web development with our comprehensive tutorial, "Creating a BMI Calculator Using JavaScript." Whether you're a novice in the realm of programming or an enthusiast seeking to augment your JavaScript skills, this step-by-step guide promises to be an illuminating experience. To kick off our journey, we'll delve into the fundamental building blocks of web development—HTML, CSS, and JavaScript. This tutorial caters to individuals ranging from absolute beginners to those looking to fortify their existing skill set. By providing a holistic understanding of these essential languages, participants can lay a solid foundation for their future endeavors in the dynamic field of web development.

    As we progress through the tutorial, we'll focus extensively on JavaScript, unraveling its intricacies in a manner accessible to beginners. The comprehensive nature of this tutorial makes it an ideal starting point for those keen on grasping the basics of JavaScript programming. Each step is accompanied by detailed explanations, ensuring that even individuals with minimal coding experience can follow along seamlessly. The core of our tutorial centers around the creation of a Body Mass Index (BMI) calculator using JavaScript. This practical project serves as a real-world application of the concepts covered, allowing participants to witness the tangible results of their coding efforts. The BMI calculator isn't just a generic implementation—it is customized to cater to both men and women, showcasing the versatility of JavaScript in addressing diverse user needs.

    A crucial aspect of this tutorial is the comprehensive walkthrough of the JavaScript code. Participants will have the opportunity to follow along with the complete code, dissecting each line to understand its purpose and contribution to the overall functionality of the BMI calculator. This hands-on approach ensures that learners not only grasp theoretical concepts but also gain practical experience in coding.

    As we progress, we'll explore the principles of responsive design, ensuring that the BMI calculator is not only functional but also visually appealing across various devices. This aspect is crucial in the contemporary landscape, where users access applications on a myriad of platforms, ranging from desktops to smartphones. Understanding responsive design principles equips participants with the skills to create user-friendly interfaces that adapt seamlessly to different screen sizes. This tutorial caters to a diverse audience. For beginners, it serves as an excellent introduction to the world of programming, offering a gentle learning curve that instills confidence. For those with some programming experience, the tutorial provides an opportunity to delve deeper into JavaScript, gaining insights into its application in web development.

    Beyond the immediate project of creating a BMI calculator, this tutorial aims to instill a broader understanding of programming possibilities. By grasping the fundamentals of JavaScript, HTML, and CSS, participants gain the foundational knowledge needed to explore more complex projects and venture into advanced areas of web development. Don't miss out on this exciting coding adventure. Whether you're looking to learn JavaScript, delve into web development, or embark on your first coding project, this tutorial offers a wealth of knowledge and hands-on experience. Follow along, ask questions, and witness the transformation of code into a functional BMI calculator. The skills acquired in this tutorial will undoubtedly pave the way for future coding endeavors, empowering you to navigate the dynamic world of web development with confidence and proficiency.

bmi.html
  
  <!DOCTYPE html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Kalkulator BMI</title>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
        <div class="form-container">
            <h2>BMI Calculator</h2>
            <form id="bmi-form">
                <div class="input-ctr">
                    <input type="number" id="weight" placeholder="Your Weight (Kg)" required>
                    <input type="number" id="height" placeholder="Your Height (Cm)" required>
                </div>
                <div class="btn-container">
                   <button id="btnCalc" type="button" onclick="calculateBMI()">
                        Calculate 
                   </button>
                   <button id="btnClr" type="button" onclick="clearInput()">
                    Clear 
               </button>
                </div>
            </form>
        </div>
        <div id="result"></div>
        <script src="script.js"></script>
    </body>
</html>
style.css

 body{
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    margin: 0;
    padding: 0;
    letter-spacing: 1.5px;
    display: flex;
    align-items: center;
    flex-direction: column;
}

h2{
    color: white;
    font-size: 35px;
}

.form-container{
    display: flex;
    align-items: center;
    flex-direction: column;
    width: 25%;
    margin: 250px auto 0;
    padding: 30px 40px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    background-color: #3e71b3;
}

.input-ctr{
    width: 400px;
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 20px;
}

::placeholder{
    font-size: 25px;
    font-style: italic;
    color: white;
}

input[type="number"]{
    font-size: 25px;
    color: white;
    width: 100%;
    padding: 20px;
    border: none;
    border-radius: 5px;
    background-color: #5f96df;
}

.btn-container{
    text-align: center;
    margin-top: 20px;
}

button{
    margin: 10px;
    padding: 15px 25px;
    color: #fff;
    border: none;
    border-radius:5px;
    cursor: pointer;
    font-size: 25px;
    letter-spacing: 1px;
    font-weight: 600;
}

#btnCalc{
    background-color: rgb(64, 220, 119);
}

#btnClr{
    background-color: rgb(252, 54, 97);
}

#result{
    margin-top: 50px;
    width: 100%;
    text-align: center;
}

p{
    padding: 0;
    margin-top: 0;
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 0.2;
}

.obesity{
    color: rgb(247,74,74);
    font-size: 50px;
}

.overweight{
    color: rgb(255, 179, 0);
    font-size: 50px;
}

.normal{
    color: rgb(37, 140, 37);
    font-size: 50px;
}

.underweight{
    color: rgb(92, 97, 92);
    font-size: 50px;
}

 
script.js
  function calculateBMI(){

    var weight = parseFloat(document.getElementById('weight').value);
    var height = parseFloat(document.getElementById('height').value)/100;

    var bmi = weight / (height * height);

    var category;
    if (bmi < 18.5){
        category = 'Underweight';
    }else if (bmi >= 18.5 && bmi < 24.9){
        category = 'Normal';
    }else if (bmi >= 25 && bmi < 29.9){
        category = 'Overweight';
    }else{
        category = 'Obesity';
    }

    var result = document.getElementById('result');
    result.innerHTML = '

Your BMI is ' + bmi.toFixed(2) + '

' + category + '

'; } function clearInput(){ document.getElementById('weight').value = ''; document.getElementById('height').value = ''; var result = document.getElementById('result'); result.innerHTML = ''; }

WATCH FULL VIDEO HERE!


Comments

Popular posts from this blog

Auto Image Slider using CSS Only

     Are you ready to learn how to create an image slider using only CSS? Look no further! In this tutorial, we'll walk you through the step-by-step process of building a sleek and modern image slider using HTML and CSS. No JavaScript required! In this tutorial We'll cover setting up the HTML structure for the slider.       This will include creating the container element and styling the slider with CSS. You'll also learn how to add transitions and animations to create a smooth sliding effect. By the end of this tutorial, you'll have a fully functional image slider that you can use on your own website. Whether you're a beginner or an experienced developer, this tutorial has something for you. So let's get started creating your own image slider using CSS today! index.html <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="css/style.css"...

Display Battery Status using HTML, CSS and Javascript

     Hey everyone, welcome to Code Instinct! In this tutorial, we're going to show you how to create a battery status indicator using HTML, CSS and Javascript. This is a great Javascript project for beginners who want to learn how to use the Battery API Javascript and create a battery level indicator. We'll also be showing you how to add a battery charging animation and CSS battery shape to make it more visually appealing.Our tutorial will cover all the steps needed to create your own battery status indicator with ease. You'll learn how to use the Battery API Javascript to get the current battery level of your device, and display it using HTML and CSS.       We'll also be covering the different types of battery indicators you can use and how to customize them to fit your website design. You'll learn how to create a battery charging animation using Javascript and CSS to give your battery status indicator a more dynamic look.At Code Instinct, we're dedi...

Glass Fill Effect using CSS Only

     In this tutorial, we will be creating a glass fill animation effect without using any SVG graphics or JavaScript. We will be using only CSS to create the animation. This animation is perfect for creating a liquid filling effect on a website. The tutorial is easy to follow and can be implemented on any website. So, if you're looking to add a cool animation effect to your website, this tutorial is for you. With this method, you can create a realistic looking glass fill animation effect without the need for any additional graphics or libraries.  index.html <html> <head> <title>TUTORIAL</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="glass-ctr"> <div class="glass"></div> <div class="water-ctr"> <div class="water"></div> ...