JavaScript programs examples with output - Javascript

JavaScript programs examples with output

JavaScript programs examples with output

Hello Guys, Welcome to our new article in the article you will get JavaScript programs examples with output.

Program-1 Write a program to find addition of two number

<html>
<body>
<h1>Program 1</h1>
<script>
var a=50;
var b=10;
document.write(“Value of a=”+a);
document.write(“<br>Value of b=”+b);
document.write(“<br>Addition of a and b=”+c);
</script>
</body>
</html>

Program-1 Write a program to find addition,Subtraction,Multiplication and  Divison of two number.

<html>
<body>
<h1>Program 1</h1>
<script>
var a=50;
var b=10;
var c=a+b;
var d=a-b;
var e=a*b;
var f=a/b;
document.write(“Value of a=”+a);
document.write(“<br>Value of b=”+b);
document.write(“<br>Addition of a and b=”+c);
document.write(“<br>Subtraction of a and b=”+d);
document.write(“<br>Multiplication of a and b=”+e);
document.write(“<br>Division of a and b=”+f);
</script>
</body>
</html>

Output

JavaScript programs examples with output

Program-2 Write a program to print simple interest

<html>
<body>
<h1>Program 2</h1>
<p>My first paragraph.</p>
<script>
var p=5000;
var r=3;
var t=2;
var si=p*r*t/100;
document.write(“Principle Amount=”+p);
document.write(“<br>Rate of interest=”+r);
document.write(“<br>Time=”+t);
window.alert(“Simple Interest=”+si);
</script>
</body>
</html>

Output

Program-3 Write a program to find area of circle.

<html>
<body>
<h1>Program 3</h1>
<script>
var r=3.5
var area=3.14*r*r
document.write(“Area of circle=”+area);
</script>
</body>
</html>

Output

For Live Class on YouTube click on the below link 

https://youtu.be/1S_iRvy4HMU

Program-4 Write a program to find the volume of cylinder and volume of cone

<html>
<body>
<h1>Program 4</h1>
<script>
var r1=3.5
var r2=5.2
var h1=7
var h2=9
var vol1=3.14*r1*r1*h1
var vol2=3.14*r2*r2*h2/3
document.write(“volumn of Cylinder=”+vol1);
document.write(“<br>volumn of Cone=”+vol2);
</script>
</body>
</html>

Output

JavaScript programs examples with output

Program 5- Write a program to enter unit price and quantity and print gross bill amount,net bill amount and discount. (Discount=5%)

<html>
<body>
<h1>Program 5</h1>
<script>
var p=10 ;
var q=100;
var gba=q*p;
var dis=gba*5/100;
var nba=gba-dis
document.write(“Gross Bill Amount=”+gba);
document.write(“<br>Discount=”+dis);
document.write(“<br>Net Bill Amount=”+nba);
</script>
</body>
</html>

Output

Now, here we completed the program where we provide the values in a program. In the next we will see Values enter at run time.

Program-6

<html>
<script>
var a1=parseInt(prompt(“Enter the value of a1 for addition”));
var b1=parseInt(prompt(“Enter the value of b1 for addition”));
var a2=parseInt(prompt(“Enter the value of a2 for subtraction”));
var b2=parseInt(prompt(“Enter the value of b2 for subtraction”));
var a3=parseInt(prompt(“Enter the value of a3 for multiplication”));
var b3=parseInt(prompt(“Enter the value of b3 for multiplication”));
var a4=parseInt(prompt(“Enter the value of a4 for multiplication”));
var b4=parseInt(prompt(“Enter the value of b4 for multiplication”));
c=a1+b1;
d=a2-b2;
e=a3*b3;
f=a4/b4;
document.write(“Addition=”+c);
document.write(“<br>Subtraction=”+d);
document.write(“<br>Multiplication=”+e);
document.write(“<br>Division=”+f);
</script>
</html>

Output

JavaScript programs examples with output

Similarly you can provide the other variable values finally here you will see the output after entering all the values.

For Live Class Watch our video on YouTube by click on the below link

https://youtu.be/MEVKaDPIrUE

Program-7

<html>
<script>
var p=parseInt(prompt(“enter principle amt”))
var r=parseInt(prompt(“enter rate of interest”))
var t=parseInt(prompt(“enter time period”))
si=p*r*t/100
document.write(“Simple Interest=”+si);
</script>
</html>

Output

JavaScript programs examples with output

 

Finally after providing the values you will get the below output

Program-8 

<html>
<script>
var r=parseInt(prompt(“Enter radius for circle..”))
var r1=parseInt(prompt(“Enter radius for cylinder..”))
var h1=parseInt(prompt(“Enter height for cylinder..”))
var r2=parseInt(prompt(“Enter radius for cone..”))
var h2=parseInt(prompt(“Enter height for cone..”))
area=3.14*r*r;
vol1=3.14*r1*r1*h1;
vol2=3.14*r2*r2*h2/3;
document.write(“Area of circle=”+area);
document.write(“<br>Volumn of cylinder=”+vol1);
document.write(“<br>Volumn of cone=”+vol2);
</script>
</html>

Output-

Here we provide the r=5,r1=7,h1=11,r2=8,h2=13, then you will get the following output

 

Thanks For Reading our Article JavaScript programs examples with output. Also share this article.

Also Check Our Latest Uploads

Popup boxes in JavaScript

Inbound and Outbound Digital Marketing

What are the JavaScript data types

 

2 thoughts on “JavaScript programs examples with output”

Leave a Comment