KEMBAR78
Java script programs | PPT
JAVA Script
For output
•<html>
•<body>
•<p id=“FA"></p>
•<script>
•document.getElementById(“FA").innerHTML = "Hello world.";
•document.write(“hellow world”)
•</script>
•</body>
•</html>
Operators
•<html>
• <body>
• <p id=“FA"></p>
• <script>
• var x = 5;
• y = 2;
• var z = x * y;
• document.write(z)
• document.getElementById(“FA").innerHTML = z;
• </script>
• </body>
•</html>
Conditions
• <html> <script>
• x=10;
• y=40;
• z=50;
• if(x>y&&x>z)
• document.write("x is greatest");
• else if(y>z&&y>x)
• document.write("y is greatest");
• else
• document.write("z is greatest")
• </script> </hmtl>
Conditions
• <html><body><script>
• number=prompt("enter value");
• if(number>=90)
• document.write("A+ grade")
• else if(number>=80)
• document.write("A grade")
• else if(number>=70)
• document.write("B grade")
• else if(number>=65)
• document.write("C grade")
• else
• document.write("Fail")
• </script></body></html>
Switch
• switch(n)
• {
• case n:
• -------context-------
• break;
• case n:
• --------context------
• break;
• default:
• -------context--------
• }
Loops• <html><body>
• <script>
• for(i=0;i<=10;i++)
• {
• document.write(“we are students of bscs”)
• }
• </script>
• </body></html>
Loops• <html><body>
• <script>
• i=o;
• while (i <= 10)
• {
• document.write(“we are students of bscs”)
• i++;
• }
• </script>
• </body></html>
Loops• <html><body>
• <script>
• i=o;
• do
• {
• document.write(“we are students of bscs”)
• i++;
• }
• while (i <= 10)
• </script>
• </body></html>
Functions
function name(parameters)
{
-----body-------
}
name(parameters);
Functions
No Return Type
No Parameters
Return type
Parameters
No Return Type
Parameters
Return Type
No Parameters
Functions
• <html> <body>
<script>
• function fa()
• {
• document.write(“hellow world”);
• }
• fa();
• </script>
• </body> </html>
NO RT
NO PM
Functions
• <html> <body>
• <script>
• function fa(a)
• {
• document.write(a);
• }
• b=10
• fa(b);
• </script>
• </body> </html>
NO RT
PM
Functions
• <html><body>
• <p id="fn"></p>
• <script>
• function fa()
• {
• x=10
• y=20
• return x * y;
• }
• document.getElementById("fn").innerHTML = fa();
• </script>
• </body> </html>
RT
NO PM
Functions
• <html><body>
• <p id="fn"></p>
• <script>
• function fa(x, y)
• {
• return x * y;
• }
• document.getElementById("fn").innerHTML = fa(4,4);
</script>
• </body></html>
RT
PM
Arrays
• <html>
• <script>
• y= new Array(“Mussadiq”,”Arslan, ””Umer”,”Ahmad”,”Asad”,”Saad”)
• x=[“Mussadiq”,”Arslan, ””Umer”,”Ahmad”,”Asad”,”Saad”)
• document.write(x[1])
• x[1]=“Farhan“
• </script>
• </html>
Operators
Operators

Java script programs