Simple Calculator in Javascript

<html>
<title>
</title>
<head>
<script type=”text/javascript” >
document.write(“<center><div style=’background-color: Green;color:wheat;text-align:center;position:relative;left:0%;top:0%;width:60%;height:50%;z-index:1′>”);
document.write(“<h1>Simple Calculator</h1><br>” );
document.write(“A = <input type=’text’ id=’001′ ><br><br>”);
document.write(“B = <input type=’text’ id=’002′><br><br><br>”);
document.write(“<input type=’button’ value=’Adition’ onclick=’add( )’>”);
document.write(“<input type=’button’ value=’Subtract’ onclick=’sub( )’>”);
document.write(“<input type=’button’ value=’Multiply’ onclick=’mul( )’>”);
document.write(“<input type=’button’ value=’Divide’ onclick=’divide( )’>”);
document.write(“<input type=’button’ value=’Mod’ onclick=’mod()’>”);
document.write(“<br><br><input type=’button’ value=’Clear All’ onclick=’clear1()’></div>”);
function changebg()
{
document.getElementById(“001”).bgcolor.value = document.getElementById(“001”).bgcolor.value + 1;
}

function clear1()
{

document.getElementById(“001″).value = ” “;
document.getElementById(“002″).value = ” “;
}

function add()
{
a = parseInt(document.getElementById(“001”).value);

b =parseInt(document.getElementById(“002”).value);
c=a+b;
alert(“Sum is =”+c);
}

function sub()
{
  a = parseInt(document.getElementById(“001”).value);

b =parseInt(document.getElementById(“002”).value);
c=a-b;
alert(“Subtraction is =”+c);
}

function mul()
{
  a = parseInt(document.getElementById(“001”).value);

b =parseInt(document.getElementById(“002”).value);

c=a*b;
alert(“Multiplication is =”+c);
}

function divide()
{
  a = parseInt(document.getElementById(“001”).value);

b =parseInt(document.getElementById(“002”).value);

c=a/b;
alert(“Division is =”+c);
}

function mod()
{
  a = parseInt(document.getElementById(“001”).value);

b =parseInt(document.getElementById(“002”).value);
c=a%b;
alert(“Modulus is =”+c);
}
</script>
</head>
<body bgcolor=”Red” id =”003″>
</body>
</html>

Output:

simple_calculator_in_javacscript

Comments

Popular posts from this blog

MATLAB code for Circular Convolution using Matrix method

Positive number pipe in angular 2+