What is Javascript?

7


Javascript:-  It is the client-side (browser side) script-based language that is used to implement business logic, validation, animation, and dynamic design view in web applications.
Javascript has been modified and implemented using a different library.
1 Jquery
2 Angular
3 Angular Js
4 Node JS
5 React
6 React native
7 Knockout
8 Particle
9 Express
Javascript Architecture:-
DOM (Document Object Model):-
Javascript provides a separate window with a document to contain and access all Html elements.
Javascript can provide accessibility to all HTML elements.




If we want to access an HTML element using javascript then we can use two different syntax
1) document.getElementById("idname").attribute
2) document.getElementsByName("elementname").attribute
<input type="text" id="txt"  />
a=document.getElementById("txt").value;
We can write Javascript under HTML documents because without an HTML document JS has no role.
     <script>
     document.write("Welcome in JS");
     alert("welcom in JS");
    </script>
note:-  if we write JAVASCRIPT internally then we should define it under the <head> section.
Complete Code with HTML and JS?
<!DOCTYPE html>
<html>
<head>
<title></title>
    <script>
     document.write("Welcome in JS");
     alert("welcom in JS");
    </script>
</head>
<body>
<p>Welcome in HTML</p>
</body>
</html>
How do we declare a variable in Javascript?
we can directly declare a variable in JS without using datatype because JS is a loosely coupled script.
Syntax:-
identifier=value
or
var identifier = vaue
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
a=100;
b=200;
c=a+b;
document.write("<h1>"+ c +"</h1>");
</script>
</head>
<body>
</body>
</html>
Example 3:-
Create a script to complete the addition of two numbers?
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">

function fun()
{
num1 = document.getElementById("txt1").value;
num2 = document.getElementById("txt2").value;
num3 = parseInt(num1)+parseInt(num2);
alert(num3);
}
</script>
</head>
<body>
 <input type="text" id="txt1" placeholder="Enter first number" />
 <br>
 <br>
 <input type="text" id="txt2" placeholder="Enter second number" />
 <br>
 <br>
 <input type="button" id="btnclick" value="Click" onclick="fun()">
</body>
</html>
Check Prime Number Program in Js:-
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function checkprime()
        {
          var a = parseInt(document.getElementById("txtnum1").value);
          c=0;
          for(i=1;i<=a;i++)
          {
                if(a%i==0)
                {
                    c++;
                }
          }  
          if(c==2)
          {
              document.getElementById("b").style.backgroundColor="Red";
              document.getElementById("res").innerHTML = "Prime";
            //  document.write("Prime");
          }
          else
          {
              //document.write("Not prime");
              document.getElementById("b").style.backgroundColor="Green";
              document.getElementById("res").innerHTML = "Not Prime";
          }
        }
    </script>
</head>
<body id="b">
    <input type="text" id="txtnum1" placeholder="Enter Number" />
    <br>
    <input type="button" value="Check" onclick="checkprime()" />
    <div id="res"></div>
</body>
</html>
Javascript String Based Program:-
1) WAP to count total vowels and consonants?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
      function countvowlcons()
      {
          var s = (document.getElementById("txtstr").value).toLowerCase();
          var v=0;
          var c=0;
          for(i=0;i<s.length;i++)
          {
              if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i] =='o' || s[i] =='u')
              {
                  v++;
              }
              else
              {
                  c++;
              }
          }
          document.write("Total vowel is "+v + "Total Consonent is "+c);
      }
    </script>
</head>
<body>
   
    Enter any String
    <br>
    <input type="text" id="txtstr" />
    <br>
    <input type="button" id="btnclick" value="Click" onclick="countvowlcons()" />
</body>
</html>

2)  WAP to check palindrome?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
      var s = "ramesh";
      var rev = "";
      for(i=s.length-1;i>=0;i--)
      {
          rev = rev + s[i];
      }
      if(s==rev)
      {
          document.write("Pallindrom");
      }
      else
      {
          document.write("Not pallindrom");
      }
    </script>
</head>
<body>
   
</body>
</html>
Another Program to Check Palindrome:-
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var s = "aman";
        var res="pallindrom";
        for(var i=0;i<s.length/2;i++)
        {
            if(s[i]!=s[(s.length-1)-i])
            {
                res = "not pallindrom ";
                break;
            }
        }
        document.write(res);
    </script>
</body>
</html>


3) WAP to count total words in String?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        s = "wecome in shiva concept solution";
        wc=0;
        for(i=0;i<s.length;i++)
        {
            if(s[i]==" ")
            {
                wc++;
            }
        }
        document.write(wc+1);
    </script>
</head>
<body>
   
</body>
</html>
Assignment:-
1) Templrature convertor from celsius to faharenhite?
2)  Create a Salary Calculator where basic, ta, da, comm,pf, leave will be entered by the user?
3)  WAP to check the password is Strong or weak (a strong password contains 3 special char, length of more than five)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        s = "12@$45*67";
        wc=0;
        for(i=0;i<s.length;i++)
        {
            if(s[i]=="@" || s[i] == '$' || s[i] == '_' || s[i]=='#' || s[i]=='*')
            {
                wc++;
            }
        }
        if(wc>=3 && s.length>5)
        {
            document.write("Password is Strong");
        }
        else
        {
            document.write("Password is Weak");
        }
       
    </script>
</head>
<body>
   
</body>
</html>
4)  WAP to count total repeated words in a paragraph?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
      var s = "welcome in java welcome in PHP java PHP Python welcome in java";
      var arr = s.split(" ");
      console.log(arr);
      rc=0;
     
      for(i=0;i<arr.length;i++)
      {
        c=0;
          for(k=0;k<i;k++)
          {
              if(arr[i]==arr[k])
              {
                  c=1;
                  break;
              }
          }
          for(j=i+1;j<arr.length && c==0;j++)
          {
              if(arr[i]==arr[j])
              {
                  rc++;
                  document.write(arr[i] + " ");
                  break;
              }
          }
      }
      document.write(rc);

    </script>
</head>
<body>
   
</body>
</html>

5)  WAP to convert String in Opposite case?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var s = "hello";
        s1="";
       for(i=0;i<s.length;i++)
       {
           asc = s[i].charCodeAt();
         
           if(asc>=65 && asc<=90)
           {
              s1 = s1  + String.fromCharCode(asc+32);
           }
           else
           {
            s1 = s1  + String.fromCharCode(asc-32);
           }
       }
       document.write(s1);
 
    </script>
</head>
<body>
   
</body>
</html>
6)  WAP to count total repeated and unique char in String?
7)  WAP to find max char, min char in each word of a paragraph?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
      var s = "welcome in java welcome in PHP java PHP Python welcome in java";
      var arr = s.split(" ");
      console.log(arr);
      rc=0;
     
      for(i=0;i<arr.length;i++)
      {
       test = arr[i];
       max=0;
       min=test[0].charCodeAt();
       for(j=0;j<test.length;j++)
       {
             if(max<test[j].charCodeAt())
             {
                 max=test[j].charCodeAt();
             }
             if(min>test[j].charCodeAt())
             {
                 min=test[j].charCodeAt();
             }
      }
      document.write(test + " Max Char "+String.fromCharCode(max) + " MIN CHAR "+String.fromCharCode(min) + " <br>");
    }
    </script>
</head>
<body>
   
</body>
</html>
8)  WAP to validate Internet URL?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var s = "http://ab.a";
        var prt = s.substring(0,5);
        var prt1 = s.substring(0,6);
        var dslash = s.substring(5,7);
        var dslash1 = s.substring(6,8);
        var dotpos = s.lastIndexOf(".");
        var slashindex = s.indexOf("/");
        var domain = dotpos-slashindex;
      //  var domain1 = dotpos-dslash1;
        var dtype = s.length-dotpos;
       
        document.write("Protocol "+ prt + "Dot position" + dotpos + "domain is "+ domain + " Slash index"+ slashindex);
        if(prt != "http:")
        {
           
           document.write("Invalid protocol ");
        }
        else if(dslash!="//" )
        {
            document.write("Invalid // ");
        }
        else if(domain<=2)
        {
            document.write("Invalid domain ");
        }
        else if(dtype<=1)
        {
            document.write("Invalid domain type ");
        }
        else
        {
            document.write("Correct domain");
        }
    </script>
</head>
<body>
    
9)  WAP to validate name and emailid and mobileno?
10)  WAP to find maximum length palindrome in a paragraph?


Array Assignments:
WAP to sort the array elements in ascending order?
WAP to find second max, first max, and third max elements in an array without sorting?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        x = [2,34,45,67,89,71,11,34]
        max=0
        smax=0
        tmax=0
        for(i=0;i<x.length;i++)
        {
            if(max<x[i])
            {
                tmax=smax;
                smax=max;
                max=x[i];
            }
            else if(smax<x[i])
            {
                tmax=smax;
                smax=x[i];
            }
            else if(tmax<x[i])
            {
                tmax=x[i];
            }
        }
        document.write(max +  " " + smax + " "+tmax);
    </script>
</head>
<body>
   
</body>
</html>
WAP to check prime elements in an array and display them?
Create a Multidimensional array and calculate addition and multiplication?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function addition()
        {
     var a = [[2,3],[4,5]];
     var b = [[4,5],[6,7]];
     var c = [[],[]];
     for(i=0;i<2;i++)
     {
         for(j=0;j<2;j++)
         {
             c[i][j] = a[i][j] + b[i][j];
             document.write(c[i][j] + " ");
         }
         document.write("<br>");
     }
    }
    function multi()
        {
     var a = [[2,3],[4,5]];
     var b = [[4,5],[6,7]];
     var c = [[],[]];
     for(i=0;i<2;i++)
     {
         for(j=0;j<2;j++)
         {
             s=0;
            for(k=0;k<2;k++)
            {
              s = s+ a[i][k]*b[k][j];
            }
            c[i][j] = s;
             document.write(c[i][j] + " ");
         }
         document.write("<br>");
     }
    }
   addition();
   multi();
    </script>
</head>
<body >
   
</body>
</html>

WAP to print only duplicate elements in the array and it should display once?
WAP to split one array into three different subarrays?
WAP to merge three arrays into one array?
Find the 10 predefined methods of an array?
MOST Important Array Interview Questions for Interview?
Check if a key is present in every segment of size k in an array?
Find the minimum and maximum element in an array
Write a program to reverse the array
Write a program to sort the given array
Find the Kth largest and Kth smallest number in an array
Find the occurrence of an integer in the array
Sort the array of 0s, 1s, and 2s
Range and Coefficient of array
Move all the negative elements to one side of the array
Find the Union and Intersection of the two sorted arrays
Level 2
Write a program to cyclically rotate an array by one
Find the missing integer
Count Pairs with the given sum
Find duplicates in an array
Sort an Array using the Quicksort algorithm
Find common elements in three sorted arrays
Find the first repeating element in an array of integers
Find the first non-repeating element in a given array of integers
Find the largest three elements in an array Time
Rearrange the array in alternating positive and negative items
Find if there is any subarray with sum equal to zero
Find Largest sum contiguous Subarray
Find the factorial of a large number
Find Maximum Product Subarray
Find longest consecutive subsequence
Find the minimum element in a rotated and sorted array
Find all elements that appear more than N/K times
GCD of given index ranges in an array
Minimize the maximum difference between the heights
Minimum number of jumps to reach the end
Find the two repetitive elements in a given array
Find a triplet that sums to a given value
Construct a N*M matrix from the user input
Find the row with the maximum number of 1’s
Print the matrix in a Spiral manner
Find whether an array is a subset of another array
Implement two Stacks in an array
Majority Element
Wave Array
Trapping Rainwater
Level 3
Maximum Index
Max sum path in two arrays
Find Missing And Repeating
Stock buy and sell Problem
Pair with given sum in a sorted array
Chocolate Distribution Problem
Longest Consecutive Subsequence
Print all possible combinations of r elements in a given array

Tags

Post a Comment

7Comments

POST Answer of Questions and ASK to Doubt

  1. Name:Nayansi purwar

    1) Temperature convertor from celsius to faharenhite?

    /*
    html
    head

    script type="text/javascript"
    celcius=40;
    var fahrenhit=(celcius*1.8)+32;
    document.write("celcius to fahrenhit:" +fahrenhit);

    script
    head



    */

    ReplyDelete

  2. /*html
    head
    script
    function Fahrenheit() {
    c=document.getElementById('Celsius').value;
    F=c*1.8000 +32.00;
    //document.write("h3" + F + "*F h3");
    //document.getElementById('show').innerHTML= F;
    // alert("" + F + "*F");
    //console.log(F);
    script
    head
    html*/

    ReplyDelete
  3. Q. WAP TO CHECK PALINDROME?
    SOL:-
    NAME:- SHIVAM RAZ VYAS

    html
    body

    h2 style="color:grey; font-size:20px;">Palindrome 1 sup ST /sup Program b:- )b /h2

    input type="text" id="txt" style="border:1px solid red; border-radius:5px; box-shadow:1px 1.2px 1.5px 0.6px red;"/

    input type="button" value="Click" onclick="shi()" style="border-radius:5px"/

    script
    function shi(){
    var n = document.getElementById("txt").value;
    var up = n.toUpperCase();
    var str = up;
    str = up.split("").reverse().join("");
    var rc = "";

    for (i=n.length-1; i>=0; i--){
    (rc= rc+n[i]);
    }
    if(n==rc){
    document.write("Yes, It is a Palindrom:- " + str);
    }
    else{
    document.write("No, It is not a Palindrome:- " + str);
    }

    }
    /script
    /body
    /html

    ReplyDelete
  4. WAP to sort the array elements in ascending order

    var numbers=[14,18,3,10,43];
    numbers.sort(function(a,b)
    {
    return a-b;
    }
    );
    document.write(numbers)

    ReplyDelete
  5. WAP to sort the array elements in ascending order

    let arr = [321, 2, 6, 23, 62, 5, 36, 245, 52, 57,423,25];
    let sortArr;
    for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr.length; j++) {
    if (arr[j] > arr[i]) {
    sortArr = arr[j]
    arr[j]=arr[i]
    arr[i]=sortArr
    }
    }
    }
    document.write("Sorted Array : "+arr)

    ReplyDelete
  6. WAP to check prime elements in an array and display them

    let arr = [321, 2, 6, 23, 62, 5, 36, 245, 52, 57, 423, 25];
    for (let i = 0; i < arr.length; i++) {
    let primeTrue = true
    for (let j = 2; j < arr[i]; j++) {
    if (arr[i] % j === 0) {
    console.log("Not a prime number : " + arr[i]);
    primeTrue = false
    break
    }
    }
    if (primeTrue) {
    document.write("Prime number in Array : " + arr[i] + "
    ")
    }
    }

    ReplyDelete
  7. WAP to print only duplicate elements in the array and it should display once

    let arr = [4, 2, 6, 23, 62, 5, 36, 245, 52, 57,6,4 ,423, 25,6,56,44,45,77,33,77];
    document.write("Given Array : " +arr +"
    ")
    let tempArr =arr
    let duplicates = new Set()
    for (let i = 0; i < arr.length; i++) {
    for (let j = i+1; j < arr.length; j++) {
    if(arr[i]===tempArr[j]){
    duplicates.add(arr[i])
    tempArr[i]="counted"
    }
    }

    }
    for (item of duplicates.values()){
    document.write("Dupilicate found : "+item+"
    ")
    }

    ReplyDelete
Post a Comment