Write a javascript program to make a simple calculator
Answer Posted / ruchi goswami
<html>
<head>
<link rel="stylesheet" type="text/css" href="css2.css">
<title> calculator </title>
</head>
<body>
<div id="wrap">
<h1> Calculator </h1>
<b> enter first number </b>
                   
<b> enter second number </b>
<form action="">
<input type="text" name="firstnum" id="first">
                   
<input type="text" name="lastnum" id="second">
</form>
<br> </br>
<button onclick="sum()"> + </button>
               
<button onclick="sub()"> - </button>
               
<button onclick="mul()"> * </button>
               
<button onclick="divi()"> / </button>
<br> </br>
<input type="text" id="result">
<p id="demo"></p>
<script>
function sum()
{
var a = Number(document.getElementById("first").value);
var b = Number(document.getElementById("second").value);
c = a+b;
document.getElementById("result").value = c;
}
function sub()
{
var a = Number(document.getElementById("first").value);
var b = Number(document.getElementById("second").value);
c = a-b;
document.getElementById("result").value = c;
}
function mul()
{
var a = Number(document.getElementById("first").value);
var b = Number(document.getElementById("second").value);
c = a*b;
document.getElementById("result").value = c;
}
function divi()
{
var a = Number(document.getElementById("first").value);
var b = Number(document.getElementById("second").value);
c = a/b;
document.getElementById("result").value = c;
}
</script>
</div>
</body>
</html>
| Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
What is NaN?
How can you identify a function?
Define an interface MilitaryPower that has the following properties: • The interface has two public static final variables which are the finite x and y coordinate (i.e. the distance of the objects should not exceed these values. These values set to 100. • The interface has a method move that moves the military power objects to the target value. The method will be implemented by the other classes. The return type should be void. B) Define an enum class Direction which contains the directions (EAST, WEST, SOUTH, NORTH). C) Define a concrete class Tank that implements MilitaryPower, has the following properties: • XCoordinate (Integer), YCoordinate (Integer) are the instance variables for this class. • All instance variables should be private. • Write a parametered constructor that takes two parameters assigning with the instance variables. • Write a set and get method each of the instance variables. • Write a method move that takes two parameters. One of them is distance which type is integer. Another is direction which type Direction. The method should to the following: o If the direction is EAST, set the x-coordinate with adding distance. o If the direction is WEST, set the x-coordinate and subtract distance from x-coordinate. o If the direction is SOUTH, set the y-coordinate with adding distance. o If the direction is NORTH, set the y-coordinate and subtract distance from x-coordinate. • Write a method toString to display the tank coordinates. D) Define an array holding 10 MilitaryPower objects, all of them being a Tank. Then display each of the object information on the screen. (display its movements and coordinates).
What is the use of window object?
What are the application of javascript?
What are escape characters in javascript?
Why do you need javascript?
Name the two functions that are used to create an HTML element dynamically?
How to achieve inheritance in javascript?
Is JavaScript a true OOP language?
What is strict mode?
How do you check if a string is a number javascript?
How to detect browser name using JavaScript?
Why extending array is bad idea?
How to add behavior to an element using javascript?