Skip to main content

Build a Simple Calculator Using HTML, CSS and JavaScript | Step-by-Step Tutorial

 

#Calculator #html #css #foryou #world #happy # website #webdesign #webdeveloper #how to #howto #trending #viral #srilanka #youtube #tiktok #blog  #howtocreate #Javascript #image #imageuploader 


You'll learn how to create a fully functional calculator using #html #css and #javascript . Follow along as we break down the process into easy-to-understand steps, from designing the user interface with HTML and CSS to adding interactive functionality with JavaScript. 🔹 Learn the fundamentals of HTML, CSS, and JavaScript. 🔹 Design a sleek and user-friendly calculator interface. 🔹 Implement basic arithmetic operations, including addition, subtraction, multiplication, and division. 🔹 Handle user input and display results in real-time. 🔹 Enhance the calculator with clear functionality. 🔹 Perfect for web development beginners and anyone looking to sharpen their skills. By the end of this tutorial, you'll have your very own #calculator that you can showcase in your web development portfolio.

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Calculator</title>
</head>
<body>
   <div class="calculator">
    <input type="text" id="display" disabled>
    <div class="buttons">
        <button onclick="clearDisplay()">C</button>
        <button onclick="appendToDisplay('*')">*</button>
        <button onclick="appendToDisplay('+')">+</button>

        <button onclick="appendToDisplay('/')">/</button>
        <button onclick="appendToDisplay('-')">-</button>
        <button onclick="appendToDisplay('.')">.</button>

        <button onclick="appendToDisplay('7')">7</button>
        <button onclick="appendToDisplay('8')">8</button>
        <button onclick="appendToDisplay('9')">9</button>

        <button onclick="appendToDisplay('4')">4</button>
        <button onclick="appendToDisplay('5')">5</button>
        <button onclick="appendToDisplay('6')">6</button>

        <button onclick="appendToDisplay('1')">1</button>
        <button onclick="appendToDisplay('2')">2</button>
        <button onclick="appendToDisplay('3')">3</button>

        <button onclick="calculate()">=</button>
        <button onclick="appendToDisplay('0')">0</button>
        <button onclick="calculate()">Enter</button>
    </div>
   </div>
    <script src="script.js"> </script>
</body>
</html>

style.css






body{
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}
.calculator{
    background-color: black;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    width: 300px;
}
#display{
    width: 90%;
    padding: 10px;
    font-size: 24px;
    border: 5px solid #009688;
    text-align: right;
    margin-bottom: 10px;
    color: black;
}
.buttons{
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
}
button{
    padding: 10px;
    font-size: 18px;
    background-color: #009688;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
    box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
button:hover{
    background-color: gray;
    color: black;
    box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}


script.js


let display = document.getElementById('display');

function appendToDisplay(value){
    display.value += value ;

}
function clearDisplay(){
    display.value = '';
}

function calculate(){
    try{
        display.value = eval(display.value);
    }catch(error){
        display.value = "Error";
    }
}










Comments

Popular posts from this blog

How to Build Your Own Image Uploader using HTML, CSS, and JS Tutorial

    Welcome to our step-by-step tutorial on creating your own image uploader using #html  , #css  , and JavaScript. In this video, we'll guide you through the process of building a simple yet effective image uploader for your web projects. With just a few lines of code, you'll learn how to create a user-friendly interface that allows users to upload images seamlessly. Whether you're a beginner or an experienced developer looking to enhance your skills, this tutorial is perfect for you. Follow along and empower yourself to create dynamic web applications with ease! Don't forget to like, share, and subscribe for more coding tutorials. Let's get started!  index.html   <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > Drag & Drop Image Uploader </ title >...

Create an Animated Switch with HTML and CSS in 2024

  Create an Animated Switch with HTML and CSS in 2024 Learn how to create an animated switch using HTML and CSS in 2024! This tutorial will guide you through the process of building a sleek and modern switch element for your website. Enhance your web development skills and stay up-to-date with the latest design trends by mastering this technique. Watch now to level up your front-end development game!  index.html  <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > Document </ title >     < link rel = "stylesheet" href = "style.css" > </ head > < body >     < label class = "switch" >         < input type = "checkbox" checked = "checked" >         < div class = "button" >  ...

Animated Switch

    index.html <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > Document </ title >     < link rel = "stylesheet" href = "style.css" > </ head > < body >     < label class = "switch" >         < input class = "cb" type = "checkbox" />         < span class = "toggle" >           < span class = "left" > off </ span >           < span class = "right" > on </ span >         </ span >       </ label >       </ body > </ html > style.css  /* The switch - the box around the slider */ .switch {     font-size : 17px ; ...