How to create an addition calculator
- Web Coding

 - Sep 6, 2020
 - 1 min read
 
Today I will be teaching you how to create an addition calculator using HTML, CSS and JavaScript
HTML
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Addition Calc</title>
 <link rel="stylesheet" href="style.css">
</head>
<body>
 <div>
 <h1>Two Number Addition Calculator</h1>
    First Number: <input type="text" name="firstNum" id="firstNum" 
 placeholder="Enter a number"> <br>
    Second Number: <input type="text" name="secondNum" id="secondNum" 
 placeholder="Enter another number"> <br>
 
 <button type="button" id="addBtn">Add</button>
 <div>Result is <span id="resultDisplay"> </span></div>
 <script src="script.js"></script>
</div>
</body>
</html>CSS
body{
 min-height: 100vh;
 display: flex;
 align-items: center;
 justify-content: center;
}JavaScript
let firstNum = document.getElementById('firstNum');
let secondNum = document.getElementById('secondNum');
let addBtn = document.getElementById('addBtn');
let result = document.getElementById('resultDisplay');
addBtn.addEventListener('click', calculate);
function calculate(){
 result.innerHTML = parseFloat(firstNum.value) + parseFloat(secondNum.value);
}If you found this blog post helpful don’t forget to check out my other projects and if you want more content follow me on
YouTube: https://www.youtube.com/channel/UC2nxqB2usQIS2c8zwVZKWEQ
Instagram: https://www.instagram.com/coding_for_the_web/
Twitter: https://twitter.com/LearnWebCoding



Comments