Friday, October 13, 2023

Calculator

<h1>Calculator</h1>
<input type="number" id="num1" placeholder="First number">
<input type="number" id="num2" placeholder="Second number">
<input type="number" id="result" placeholder="Result">
<br />
<button type="button" onclick="plus()">+</button>
<button type="button" onclick="minus()">-</button>
<button type="button" onclick="product()">*</button>
<button type="button" onclick="divide()">/</button>
<script>
result=0.;
// Function to perform the calculation
function plus() {
z=0.;x=0.;y=0.;
x = document.getElementById('num1').value;
y = document.getElementById('num2').value;
z = Number(x) + Number(y);
// Display the result
document.getElementById('result').value = z;
}
function minus() {
result=0.;x=0.;y=0.;
x = document.getElementById('num1').value;
y = document.getElementById('num2').value;
result = x - y;
// Display the result
document.getElementById('result').value = result;
}
function product() {
result=0.;x=0.;y=0.;
x = document.getElementById('num1').value;
y = document.getElementById('num2').value;
result = x * y;
// Display the result
document.getElementById('result').value = result;
}
function divide() {
result=0.;x=0.;y=0.;
x = document.getElementById('num1').value;
y = document.getElementById('num2').value;
result = x / y;
// Display the result
document.getElementById('result').value = result;
}
</script>

No comments:

Post a Comment

N-point Star in Microsoft Visual Studio Console App

#include <windows.h> #include <cmath> #include <iostream> LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,...