JavaScript Micro Project: Simple Calculator
This micro project demonstrates a simple calculator built using HTML and JavaScript. The
calculator can perform basic operations like addition, subtraction, multiplication, and division.
Objectives:
1 Understand basic JavaScript programming.
2 Learn how to interact with HTML elements using JavaScript.
3 Create a simple calculator application.
Tools Required:
1 HTML
2 JavaScript
3 Web Browser (Chrome, Edge, etc.)
Sample Code:
<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
<script>
function add(){
var a = parseFloat([Link]("num1").value);
var b = parseFloat([Link]("num2").value);
[Link]("result").innerHTML = "Result: " + (a + b);
}
</script>
</head>
<body>
<h2>Simple Calculator</h2>
Number 1: <input type="text" id="num1"><br><br>
Number 2: <input type="text" id="num2"><br><br>
<button onclick="add()">Add</button>
<p id="result"></p>
</body>
</html>
Conclusion:
This project shows how JavaScript can be used to perform calculations and interact with user inputs
in a web page. It is a basic example for beginners learning JavaScript.