Wednesday 27 January 2021

java script built-in function

 JAVASCRIPT STRING FUNCTION

<script>


s1="avadhtutor";        

s2="Javascript";

document.write(s1);

//convert your string as bold or strong using .bold() function

document.write(s1.bold()+ "<br>");

                //convert your string as italics using .italics() function

document.writeln("<br>italics = " + s1.italics());

                //convert your string as capital letter, converts a string to uppercase letters

document.writeln("<br>This is Upper Case = " + s1.toUpperCase());

                //convert your string as Small letter, converts a string to LowerCase letters

document.writeln("<br>"+s1.toLowerCase());

                //returns the character at the specified index in a string

document.writeln("<br>charAt = " + s1.charAt(4)); 

                //merge a string using concat() function

document.writeln("<br>concat = "+ s1.concat(s2));

                //returns the position of the first occurrence of a specified value in a string

document.writeln("<br>index of = " + s1.indexOf('i'));

document.writeln("<br>index of = " + s1.indexOf('a'));

                //returns the position of the Last occurrence of a specified value in a string

document.writeln("<br>last index of = " + s1.lastIndexOf('i'));

                //extracts parts of a string, beginning at the character at the specified position, and returns                     //the specified number of index

document.writeln("<br>substr = " + s2.substr(2,4));

                //first is index and last is char position

        document.writeln("<br>substring  = " + s1.substring(3,4)); 

                //method searches a string for a specified value, and returns the position of the match. The                     //search value can be string or a index

document.writeln("<br>search = " + s2.search("v")); //character wise search index

                //returns a new string where the specified values are replaced.

document.writeln("<br>replace = " + s2.replace("v","j"));

</script>

___________________________________________________

JAVA SCRIPT MATH FUNCTION

<script >

                //abs(): return positive value

document.writeln("<br>abs = " + Math.abs(-2.10));

                //returns the value of x to the power of y (xy)

document.writeln("<br>Pow = " + Math.pow(3,3));

                //create a proper random function to use for all random integer purposes

document.writeln("<br>Random = " + Math.random());

                // rounds a number to the nearest integer

document.writeln("<br>Round = " + Math.round(124.900));

                //method rounds a number UPWARDS to the nearest integer

document.writeln("<br>Ceil = " + Math.ceil(2.99));

document.writeln("<br>Ceil = " + Math.ceil(-12.999));

                //method rounds a number DOWNWARDS to the nearest integer

document.writeln("<br>Floor = " + Math.floor(11.5));

document.writeln("<br>Floor = " + Math.floor(-11.999));

                //returns the number with the highest value

document.writeln("<br>Max = " + Math.max(15,20,10,50,5,120,1));

document.writeln("<br>Max = " + Math.max(-15,-20));

                //returns the number with the lowest value

document.writeln("<br>Min = " + Math.min(15,20,10,50,3));

document.writeln("<br>Min = " + Math.min(-15,-20));

                //returns the square root of a number

document.write("<br>square root" +Math.sqrt(144));

document.write("<br>Square root"+ Math.sqrt(81));

document.write("<br>Square root"+ Math.sqrt(625));

</script>


_________________________________________

DATE & TIME FUNCTION IN JAVASCRIPT

<script>

var t = new Date();

//get full system time

document.write("Get Full Time:"+ t.getTime() + "<br />");

//get current hours of system

document.write("Get Houurs" +t.getHours()+ "<br />");

//get current  Minutes of system

document.write("Get Minutes" + t.getMinutes() + "<br />");

//Get Current System Seconds 

document.write("Get Seconds " + t.getSeconds() + "<br />");

//Get Current MiliSeconds

document.write("Get MilliSeconds" +t.getMilliseconds() + "<br>");

//return integer day values

document.write("Get Day " + t.getDay() + "<br />");

//return integer month values

document.write("Get Month " + t.getMonth() + "<br />");

//get four digit full year

document.write("Get Year " + t.getFullYear() + "<br />");

</script>

___________________________________________

JAVASCRIPT ARRAY FUNCTION

<script >

//join(): join or merge  or conacat two or more array using join() function

var arr = new Array();

arr[0] = "All";

arr[1] = "Programming";

arr[2] = "Avadh ";

arr[3] = "Tutor";

document.write(arr +"<br> ");

document.write(arr[0]+"<br>");

document.write(arr.join() + "<br />");

document.write("Name:"+arr.join("<br>Name:"));

</script>

___________

<script type="text/javascript">

//delete array element runtime using pop() array function, delete last element using POP()

var arr = new Array();

arr[0] = "Learn";

arr[1] = "All";

arr[2] = "Programming";

arr[3] = "With";

arr[4] = "youtube.com/avadhtutor";

document.write("<br><br>"+arr + "<br />");

document.write(arr.pop() + "<br />");

document.write(arr+"<br>");

document.write(arr.pop() + "<br />");

document.write(arr+"<br>");

document.write(arr.pop() + "<br />");

document.write(arr+"<br>");

</script>

__________________________

<script type="text/javascript">

//push() : is used to insert or new  elements inside a array using push() function

var arr = new Array(3);

arr[0] = "Scripting";

arr[1] = "Languages";

arr[2] = "youtube.com/avadhtutor/playlists";

document.write("<br><br><br>" +arr + "<br />"); 

document.write(arr.push("jay") + "<br />");

document.write(arr+"<br>");

</script>



Learn all 
Programming and Scripting 
Languages with 

youtube.com/avadhtutor/playlists


 

Tuesday 19 January 2021

JavaScript Events

 JavaScript Events

onclick(): click on object (elements) then event are occurred

<input type=button value="click me" onclick="alert(' Welcome to Onclick event')">

________________________


ondblclick(): ondblclick event occurred when two time click on object for example:

<script>

function sum()

{

a= 20;

b=30;

c = a+b;

document.write(c);

}

</script>

<input type=button value="addition" ondblclick="sum(); ">

___________________________

onmousemove() or mouseover: 

- this event is working with your cursor is going inside a Object then Mousemoved are Fire

- if your cursor are go inside an elements then move event occured

<script>

    function news()

    {

    alert("todays we are worked with JavaScript events \n All                 Subjects are Important for Future");

    }

</script>

<br><br>

<p style="background-color:yellow;" onmousemove="alert('this is a Mouse Move Event');">welcome</p>


<br><br>


<input type=button onmousemove="news();" value="NEWS">


Mouseover():


<script>

function abc()

{

alert("Welcome to Mouse Move event");

}

function xyz()

{

alert("Welcome to Mouse Over Event");

}\

</script>

<input type=button onmousemove="abc();" value="    Mouse Move    ">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type=button onmouseover="xyz();" value="    Mouse Over    ">

_____________________


MouseOut(): mouse out is working with if you are loss or leave the cursor on object 

<script>

function test()

{

alert("This is a Mouse Out event");

}

</script>

<input type=button onmouseout="test();" value="    Mouse Out    ">


___________________________

onfocus(): this event occurred when you tab or click on object

- The onfocus event is most often used with <input>, <select>, and <a>.


<script>

function y()

{

alert("Please Not Write Content Here");

document.frm.t1.value="Avadh Tutor";

function z()

{

document.frm.t2.value="";

}

</script> 

<form name="frm">

<input type="text" name="t1"  value="" onfocus="y();" ><br>

<input type="text" name="t2" value="" onfocus="z();">

</form>


Example 2: Onfocus with Color Change

<script>

function setStyle(x)

{

var a = document.getElementById(x);

document.getElementById(x).style.background="black";

document.getElementById(x).style.color="white";

document.getElementById(x).style.fontSize="10";


}

</script>

First name: <input type="text" onfocus="setStyle(this.id)" id="zxcvxx">

<br />

Last name: <input type="text" onfocus="setStyle(this.id)" id="cvx">

__________________________________


onkeyup(): when your key is up inside a keyboard

- when the user releases a key

<script>


function y()

{

alert("Please Not Write Content Here");

document.frm.t1.value="Bhavin";

function z()

{

document.frm.t2.value="";

}

</script> 

<form name="frm">

<input type="text" name="t1"  value="" onkeyup="y();" ><br>

<input type="text" name="t2" value="" onkeyup="z();">

</form>

__________________________

onChange(): when the value of an element has been changed, For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed, onchange event occured when you change your data (value)

Example : 

<script>

function abc()

{

alert(document.frm.product.value);

}

</script>

</head>

<body>

<form name="frm" method=post>

<select name="product" onchange="abc();" >

<option value="this">INDIA</option>

<option value="is">B</option>

<option value="best">C</option>

<option value="you">D</option>

</select>

</form> 

___________________________________________________

onSubmit(): onSubmit event is Work with form with Submit Button, When you click on Submit then onsubmit event will be fired

Example:

<script>

function abc()

{

alert(document.frm.nm.value);

alert(document.frm.pass.value);


}

</script>


<form name=frm  onsubmit="abc()" method=post>

name<input type=text name=nm value="">

password<input type=password name=pass value="">

<input type=submit value="click now"  >

</form>

_____________________________________________________

onBlur() : most often used with form validation code

<input type="text" id="myInput" onfocus="focusFunction()" onblur="blurFunction()" placeholder="Enter Your Name">


<script>

function focusFunction() {

   document.getElementById("myInput").style.background = "tomato";

}


function blurFunction() {

   document.getElementById("myInput").style.background = "blue";

}

</script>

_________________________________________

onReset(): occurs when a form is reset (clear).

Example :

<form onreset="my()">

  Enter name: <input type="text" placeholder="Enter Name">

  <input type="reset">

</form>

<script>

function my() {

  alert("The form was reset");

}

</script>



 



 



JavaScript Array

 What is Array:

- array is a single variable that is used to store different elements.

- by default index of array is 0

- Array is stored multiple values inside a Single Variable Using New Keyword

____________________________________


Difference Between Array and Variable

- Array is Stored Multiple Values inside a Single variable using New Keyword

- Variable is Stored only Single value At a time 

 Example of Variable and Array:

<script>

//variable is store run time only one value at a time

a = 1,2,3,4;

document.write(a);

document.write("<hr>");


        //array

a = new Array(10,20,30,40,100);

document.write(a);

</script>

Output of variable:

1

Output of Array:

1,2,3,4

_______________________________________________

Index wise Array Printing:

<script>

//index wise array fetch

a = new Array(10,30,40,50,100)

document.write(a);

document.write("<hr>");

document.write(a['1']);

document.write("<hr>");

document.write(a['4']);

</script>

Output:

10,30,40,50,100

_____________

30

_____________

100

______________________________________________________

Array With ForLoop:

<script>

jay = new Array("jayesh","kishan","nayan",30,40);

document.write(jay[0]);

document.write("<hr>");

for(i=0;i<=4;i++)

{

alert(jay[i]);

document.write("Your data is:"+jay[i]+"<br>");

}

</script>



Sunday 10 January 2021

JavaScript Dialog Boxes

 JAVASCRIPT DIALOGBOX

There are three types of Dialog Boxes are available in java Script

- Alert()

- Confirm()

- Prompt()

___________________________________________________________

alert() : An alert box is used if you want to sure information comes through to the user.

Example 1:

<script>

document.write("Dialog Boxes");

alert("Welcome to My BOX");

</script>


Example 2: Addition

<script>

a = 10;

b= 20;

c = a+b;


document.write(c);

alert("Addition is : "+c);


</script>


Example 3: alert with Button

<input type=button value="Click Me" onclick="alert(' Welcome to JavaScript')"> 

<br><br>


<input type=button value="Register" onclick="alert(' Welcome to MY Alert BOX')"> 

<br><br>


<input type=button value="HI Friends" onclick="alert(' This is Scripting Language')"> 

<br><br>


__________________________________________________

Confirm(): A confirm box is often used if you want the user to verify or accept something. confirm box provide two buttons OK and Cancel

Example:

<script>

alert("Thanks for Visit My WebSite");

confirm("Are Your Sure to Delete ....");

</script>

______________________________________________________

Prompt(): A prompt box is often used if you want the user to input a value before entering a page. prompt box provide input box with OK and cancel button when click on OK then return return if you click on cancel button then return false

Example 1: 

<script>

//getiing a values from the user using Prompt Box

prompt("Enter NO");

</script>


Example 2: 

<script>

i = prompt("Enter Your Name");

document.write("Your Name is :"+i);

</script>


Example 3:

<script>

//prompt getting a by default values are string


//Converting a String to Integer using parseInt() 


a= parseInt(prompt("Enter No")); 

b = parseInt(prompt("Enter No2")); 

c = a+b; 

document.write("Addition is : "+c);

</script>








Conditional Statement Using Java Script

 Java Script Conditional Statement

IF... ELSE Statement:

The if/else statement executes a block of code if a specified condition is true ther wise false.

Example: 
<script>
a= 10;
b =10;
if(a==b)
{
document.write("<h1>Avadh Tutor</h1>");
alert("All Programming languages ");
document.write("Thanks For Watch");
}
else
{
alert("Welcome to Avadh tutor");
}
if(a<b)
{
document.write("<h1>please Subscribe Our Blog</h1>");
alert("youtube.com/avadhtutor");
document.write("pandyaripal.blogspot.com");
}
else
{
alert("all programming are here");
}
if(a>b)
{
document.write("<h1>Greater then</h1>");
alert("True");
document.write("A is Small");
}
else
{
alert("abcd");
}
</script>

_____________________________________________________

IF ..... ELSE IF..... 

Example:

<script type="text/javascript">

var a=parseInt(prompt("Enter No A",""));


var b=parseInt(prompt("Enter No B",""));

if(a<b)

{

document.write("A Is Less Then Of 20 <br>");

}

else if(a==b)

{

document.write("A is equal to B <br>");

}

else if(a<50)

{

alert("hello");

}

else

{

alert("this is a alert box");

}

</script>

__________________________________________________________

Switch Statement using Java Script:

Example:

<script type=text/javascript>

var d=new Date();

abc=d.getDay();

a = parseInt(prompt("enter Switch",""));

switch (a)

{

default:

  alert("no case define");

break;

case 0:

document.write("Hello");

break;

case 1:

document.write("Monday");

break;

case 2:

  document.write("welcome");

  break;

case 3:

  document.write(" Tamene Game e rakho");

  break;

case 4:

  document.write("Sleepy THUS");

  break;

case 5:

  document.write("Sleepy FRI");

  break;

case 6:

alert("end of");

break;

}

</script> 

___________________________________________________________

Learn All programming and Scripting languages with youtube.com/avadhtutor/



What is While Loop? Example of While Loop in Java Script

 WHILE LOOP

 - A while loop in C programming repeatedly executes a target statement as long as a given condition is true.

 - The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true.

______________________________________

Syntax of While Loop:

    var initialization;

    while(condtion)

    {

        Statement

        increment/ decrement

    }

_______________________________________

Example of While Loop:

<script type="text/javascript" language="javascript">

//while loop

i=0;

b=0;

while (i<5)

{

  document.write("The number is " + i)

  document.write("<br />");

while(b<=3)

{

alert(b);

b++;

}

        i++;

}

</script>

_______________________________________

learn All Programming and Scripting languages with youtube.com/avadhtutor




    

Java Script operators

JAVA SCRIPT OPERATOR

Following Operator Provide by Java Script: Arithmetic, Assignment, Comparison, Logical

 


Learn All programming and Scripting Languages with youtube.com/avadhtutor



Friday 8 January 2021

Java Script ForLoop Example

 



JAVASCRIPT FORLOOP EXAMPLES
Example 1:  Simple ForLoop
<script>
 /*
Syntax:
for(intializ;conditional; increment / decrement)
{  
coding
*/
for(i=1;i<=5;i++)
{
document.write(i);
}
</script>

Output : 12345


Example 2: ForLoop with Space

<script>
        for(i=1;i<=5;i++)
{
document.write(i+" ");
}
</script>
Output: 1 2 3 4 5


Example 3: Multiple Space Using ForLoop

<script>
        for(i=1;i<=5;i++)
{
document.write(i+" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
}
</script>
Output: 1     2     3    4     5


Example 4: Print Data in Next Line Using ForLoop

<script>
        for(i=1;i<=5;i++)
{
document.write(i+"<br>");
}
</script>

Output:
1
2
3
4
5


Example 5: ForLoop with Color Formatting

<script>

for(i=1; i<=10; i++)
{
document.write("<font color=red>Number Is:<font><font color=blue>"+i+"</font><br>");
}

</script>



Example 6: star * Pyramid Printing Using ForLoop

<script>
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
document.write("*  ");
}
document.write("<br>");
}
</script>

Output:
*
* *
* * *
* * * * 
* * * * *

Example 7: Pyramid Printing Using ForLoop

<script>
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
document.write(j+" ");
}
document.write("<br>");
}
</script>

Output:
1
1 2
1 2 3 
1 2 3 4
1 2 3 4 5


Example 8: Descending Numbers using For Loop

<!-- 10 9 8 7 6 5 ...1 -->
<script>
for(i=10; i>=1;i--)
{ document.write(i+" "); }

</script>


Example 9 : ODD Number Printing Using JavaScript

<script>
// 1 3 5 7 9 
for(i=1; i<=10;i=i+2)
document.write(i+" ");
}

</script>


Example 10 : Even Number Printing Using javaScript

<script>
//0 2 4 6 8 ... 
for(i=0; i<=10;i=i+2)
{
         document.write(i+" "); 
     }

</script>








Variable Declaration Using Java Script

 Java Script variables

Variable are containers that can stores user define values

Define variable using var sign

without any sign variable accessible are flexible and usable

______________________________________________________

Example 1:  Simple variable Declaraton

<script>    

    a = "jay";

    document.write(a);

</script>


Example 2: Simple Calculation

<script>

a=20;

b=30;

c = a+b;

document.write(c);

</script>


Example 3: Concatenate a  variables (Merge)

<script>

var a="jay";

var b="raj";

document.write(a+"<br>"); //single variable access

document.write(b+"<hr>"); //single variable access


/* Concating a Variable (Merge) */

document.write(a,b); //merge variable using (,) sign

document.write(a+b); //merge variable using + sign

</script>


Example 4: Simple Calculations with variable with HTML Formatting

<script>


x= 30;

y = 40;

z = x+y;

document.write("<font color=red>SUM IS: </font><font color=green>",z +"</font><br>");


z = x-y;

document.write("<font color=red>SUB IS: </font><font color=green>",z +"</font><br>");


z = x*y;

document.write("<font color=red>MUL IS: </font><font color=green>",z +"</font><br>");


z = x/y;

document.write("<font color=red>DIV IS: </font><font color=green>",z +"</font>");


</script>


___________________________________________

All Programming languages step by step with youtube.com/avadhtutor/playlists/



Simple Example of Java Script

 Simple Example are Listed Here

Example 1: simple printing Statement, java script with html, java script with CSS

<script>

document.write("Hello Welcome");

document.write("<marquee>welcome to JS</marquee>");

document.write(" <p style='color:red; background-color:blue; '>welcome CSS</p>   ");

</script>

OutPut here :





Example 2:  Simple Calculation Using JavaScript
<script>
        document.write(3+2);
document.write("<br>");
document.write(3*2);
document.write("<br>");
document.write(3/2);
</script>

Output here:


Learn All Programming and Scripting languages with youtube.com/avadhtutor/




Introduction of Java Script

 : Introduction of JavaScript:

What is JavaScript:

JavaScript is the Programming Language for the Web.

JavaScript can update and change both HTML and CSS.

JavaScript is the world's most popular programming language.

JavaScript is easy to learn.

JavaScript is a dynamic computer programming language. It is lightweight and most commonly used as a part of web pages, whose implementations allow client-side script to interact with the user and make dynamic pages. It is an interpreted programming language with object-oriented capabilities.

________________________________________________________

ADVANTAGES OF JAVA SCRIPT:

Less server interaction - You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.

Immediate feedback to the visitors - They don't have to wait for a page reload to see if they have forgotten to enter something.

Increased interactivity - You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.

Richer interfaces - You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.

Easy to Use :  Java Script Provide User Friendly Environment

_________________________________________________________

DISADVANTAGES OF JAVA SCRIPT:

Client-side JavaScript does not allow the reading or writing of files. This has been kept for security reason.

JavaScript cannot be used for networking applications because there is no such support available.

JavaScript doesn't have any multi-threading or multiprocessor capabilities.

___________________________________________________________

Steps to create First Program in Java Script:

Step 1: Open Any Editor Like (Notepad, Notepad ++, Sub Lime ....)

Step 2: Write Below Code inside Your Page

<script>

    document.write("welcome to JavaScript");

</script>

_______________________________________________________________

Save this File as a 1.html


Open Your Browser and RUN it: (Output Below)