Breaking

Post Top Ad

Your Ad Spot

Activity # 13

JavaScript function activity

 

JavaScript function activity

write JavaScript program for arithmetic operations using functions and prompt()method

 

 

 

<!DOCTYPE html>

<html>

<head>

<title></title>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Latest compiled and minified CSS -->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">


<!-- jQuery library -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>


<!-- Latest compiled JavaScript -->

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

<style type="text/css">

.container{

margin-top: 20px;

width: 52.75%;

height: 100%;

padding-bottom: 20px;

background-color: rgb(217,221,207);

border: 2px solid gray;

}

h2{

color: blue;

font-size: 35px;

font-weight: bold;

text-align: center;

font-family: new time;

}

h3{

color: red;

font-weight: bold;

}

p{

color: black;

font-size: 20px;

font-weight: bold;

}

.abc{

background-color: white;

height: 250px;

padding-top: 30px;

padding-left: 10px;

}

button{

font-weight: bold;

height: 40px;

}

button:hover{

background-color: pink;

color: red;

border: 1px solid gray;

}

.bt123{

padding-top: 10px;

}

</style>

</head>

<body>

<div class="container">

<h2>SIMPLE ARTHMATIC CALCULATOR</h2><hr>

<h3>Output:</h3>

<div class="abc">

<p id="demo1"></p>

<p id="demo2"></p>

<p id="demo3"></p>

<p id="demo4"></p>

</div>

<center><div class="bt123">

<button onclick="sum()">Click to Add 2 digits</button>

<button onclick="sub()">Click to Subtract 2 digits</button>

<button style="margin-top: 10px;" onclick="multiply()">Click to Multiply 2 digits</button>

<button style="margin-top: 10px;" onclick="division()">Click to Divide 2 digits</button>

</div></center>

<script type="text/javascript">

function sum(){

var a,b, sum;

a = prompt("Enter first digit");

b = prompt("Enter second digit");

sum = parseInt(a)+parseInt(b);

document.getElementById('demo1').innerHTML = "The Sum of two digits = " + sum;

}


function sub(){

var a,b, sub;

a = prompt("Enter first digit");

b = prompt("Enter second digit");

sub = parseInt(a)-parseInt(b);

document.getElementById('demo2').innerHTML = "Sub of two digits = " + sub;

}


function multiply(){

var a,b, multiply;

a = prompt("Enter first digit");

b = prompt("Enter second digit");

multiply = parseInt(a)*parseInt(b);

document.getElementById('demo3').innerHTML = "Multiply of two digits = " + multiply;

}


function division(){

var a,b, division;

a = prompt("Enter first digit");

b = prompt("Enter second digit");

division = parseInt(a)/parseInt(b);

document.getElementById('demo4').innerHTML = "Divide of two digits = " + division;

}

</script>

</div>

</body>

</html>

 

 



No comments:

Post a Comment

  How to Submit the Practical Exam on Portal EdTechWorx  

Post Top Ad

Your Ad Spot

Pages