PROMPT CALCULATOR SWAP LARGEST SMALLEST FACTOR FACTORIAL AND SUM OF SERIES PROGRAM

 SUM OF SERIES :

document.write("it works Sum of series 1 2 3 4 5<br>");
var sum = 0;
[1,2,3,4,5].forEach(function(number) {
  sum += number;
});
document.write("SUM= "+sum +"<br>");

FACTORIAL:

<!DOCTYPE html>
<html>
<head><title> </title></head>
<style type="text/css">
*{
    background: #d2d5d8 ;
    
}   
h1{
    display: flex;
    justify-content: center;
    align-items: center;
}
::selection{
  background-color: #dddd2a;color:black;}
</style>
<body><h1>
    <script type="text/javascript">
       

a= parseInt(prompt("Find Factorial: "));
// set factorial ans f as 1
f=1;
// if given no is positive
if(a>0)
{
    // decrementing loop
    for(i=a;i>0;i--){
        f= f * i;   
    }
    document.write(`The Factorial of ${a} is ${f}`);
}else if(a==0){
    document.write(`The Factorial of 0 is 1`);   
}
else{
    document.write(`Please Enter Unsigned No. `);
}

</script></h1></body></html>


FACTOR :

// program to find the factors of an integer

// take input
document.write("<br> factors of an integer 40<br>");
const num = 40;

document.write(`The factors of ${num} is:`);
i2="";

// looping through 1 to num
for(i = 1; i <= num; i++) {

    // check if number is a factor
    if(num % i == 0) {
        i2=i2 +" "+ i;
    }
}
document.write(`<br>  ${i2} <br>`);


LARGEST & SMALLEST :


document.write("<br>The largest number from -20 20 0 <br>");
const num1 = 20;
const num2 = -20;
const num3 = 0;
let largest,smallest;

// check the condition
if(num1 >= num2 && num1 >= num3) {
    largest = num1;
}
else if (num2 >= num1 && num2 >= num3) {
    largest = num2;
}
else {
    largest = num3;
}
// check the condition
if(num1 < num2 && num1 < num3) {
    smallest = num1;
}
else if (num2 < num1 && num2 < num3) {
    smallest = num2;
}
else {
    smallest = num3;
}

// display the result
document.write("The largest number is " + largest+"<br>");
document.write("The smallest number is " + smallest+"<br>");


SWAP PROGRAM :

//JavaScript program to swap two variables
document.write("<br> swap two variables 30 and 20 <br>");
//take input from the users
let a = 20;
let b = 30;

//create a temporary variable
let temp;

//swap variables
temp = a;
a = b;
b = temp;

document.write(`The value of a after swapping: ${a} <br>`);
document.write(`The value of b after swapping: ${b} <br>`);


CALCULATOR :

<!DOCTYPE html>  
<html>  
<head>  
<title>  
Calculator Program in JavaScript  
</title>  
 
<!-- Begins the JavaScript Code -->  
<script>  
 
// Use insert() function to insert the number in textview.  
function insert(num)   
{  
document.form1.textview.value = document.form1.textview.value + num;  
}  
 
// Use equal() function to return the result based on passed values.  
function equal()  
{  
var exp = document.form1.textview.value;  
if(exp)  
{  
document.form1.textview.value = eval(exp)  
}  
}  
 
/* Here, we create a backspace() function to remove the number at the end of the numeric series in textview. */  
function backspace()  
{  
var exp = document.form1.textview.value;  
document.form1.textview.value = exp.substring(0, exp.length - 1); /* remove the element from total length ? 1 */  
}  
 
 
</script>  
 
<!-- Start the coding for CSS -->  
<style>  
/* Create the Outer layout of the Calculator. */  
.formstyle  
{  
width: 300px;  
height: 330px;  
margin: 20px auto;  
border: 3px solid skyblue;  
border-radius: 5px;  
padding: 20px;  
text-align: center;  
background-color: grey;  
}  
 
/* Display top horizontal bar that contain some information. */  
h1 {  
    text-align: center;  
    padding: 23px;  
    background-color: skyblue;  
    color: white;  
    }  
input:hover  
{  
background-color: green;  
}  
      
*{  
margin: 0;  
padding: 0;  
}  
 
/* It is used to create the layout for calculator button. */  
.btn{  
width: 50px;  
height: 50px;  
font-size: 25px;  
margin: 2px;  
cursor: pointer;  
background-color: red;  
color: white;  
 
}  
 
/* It is used to display the numbers, operations and results. */  
.textview{  
width: 223px;  
margin: 5px;  
font-size: 25px;  
padding: 5px;  
background-color: lightgreen;  
}     
      
</style>  
</head>  
<body>  
<h1> Calculator Program in JavaScript </h1>  
 <div class= "formstyle">  
 <form name = "form1">  
 <input class= "textview" name = "textview">  
 </form>  
 <center>  
 <table >  
 <tr>   
    <td> <input class = "btn" type = "button" value = "C" onclick = "form1.textview.value = ' ' " > </td>  
    <td> <input  class = "btn" type = "button" value = "B" onclick = "backspace()" > </td>  
    <td> <input  class = "btn" type = "button" value = "/" onclick = "insert('/')" > </td>  
    <td> <input class = "btn" type = "button" value = "x" onclick = "insert('*')" > </td>  
    </tr>  
      
     <tr>   
    <td> <input class = "btn" type = "button" value = "7" onclick = "insert(7)" > </td>  
    <td> <input class = "btn" type = "button" value = "8" onclick = "insert(8)" > </td>  
    <td> <input class = "btn" type = "button" value = "9" onclick = "insert(9)" > </td>  
    <td> <input class = "btn" type = "button" value = "-" onclick = "insert('-')" > </td>  
    </tr>  
      
     <tr>   
    <td> <input class = "btn" type = "button" value = "4" onclick = "insert(4)" > </td>  
    <td> <input class = "btn" type = "button" value = "5" onclick = "insert(5)" > </td>  
    <td> <input class = "btn" type = "button" value = "6" onclick = "insert(6)" > </td>  
    <td> <input class = "btn" type = "button" value = "+" onclick = "insert('+')" > </td>  
    </tr>  
      
     <tr>   
    <td> <input class = "btn" type = "button" value = "1" onclick = "insert(1)" > </td>  
    <td> <input class = "btn" type = "button" value = "2" onclick = "insert(2)" > </td>  
    <td> <input class = "btn" type = "button" value = "3" onclick = "insert(3)" > </td>  
    <td rowspan = 5> <input class = "btn" style = "height: 110px" type = "button" value = "=" onclick = "equal()"> </td>  
    </tr>  
    <tr>  
    <td colspan = 2> <input class = "btn" style = "width: 106px" type = "button" value = "0" onclick = "insert(0)" > </td>  
    <td> <input class = "btn" type = "button" value = "." onclick = "insert('.')"> </td>  
    </tr>  
    </table>  
    </center>  
 </div>  
 </body>  
 </html> 


PROMPT :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title> TAKE A NUM FIND THE FACTORIAL OF A GIVEN NO USING PROMPT</title>
</head>
<body>

    <script type="text/javascript">
       
a= parseInt(prompt("Enter The Value of A: "));
b= parseInt(prompt("Enter The Value of B: "));

document.write("The sum is "+ eval(a+b));       
document.write(`The sum is ${a}+${b}`);   
    </script>
</body>
</html>


JAVASCRIPT BASIC OUTPUT :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title> </title>
</head>
<body>
    <script type="text/javascript">

// document.write("this is our first class"+"<br>");
// document.write("<p>this is second class</p>");
       
// alert("This is very hot day");

// confirm("This is very hot day");

// var a= prompt("This is very hot day");
// console.log(a);
    </script>
</body>
</html>

Comments

Popular posts from this blog

PALINDROME NUMBER

CONVERT CARTESIAN COORDINATES TO POLAR COORDINATE

FIBONACCI SERIES