0% found this document useful (0 votes)
4 views

CSS Notes CH 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CSS Notes CH 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

CLIENT SIDE SCRIPTING LANGUAGE

CODE-22519
Examination Scheme
Theory-100
Practical-50
COURSE OUTCOMES(COs)
a) Create interactive web pages using program flow control structure.
b) Implement arrays and functions in javascript.
c) Create event based web forms using javascript.
d) Use javascript for handling cookies.
e) create interactive webpages using regiular expressions for validations.
f) Create menus and navigations in web pages
Unit-2 Array, Function and String
Total-14 Marks

• 2.1 Array :Declaring an Array, Initializing an Array


A variable which can store more than one value.
Example: const stud=[“abc”, “xyz”, “....”];
Using new keyword:
Example: const stud = new array[“abc”, “xyz”, “....”];
• Defining an Array Elements
Example: const stud[0]= “abc”;
Unit-2 Array, Function and String

• Looping an Array:
Example: const num=[10,20,30,40];
let text= “ ”;
num.forEach(fun);
function fun(value){
txt += value + “<br>”;
}
Unit-2 Array, Function and String
• Adding an Element:
Example: const stud=[“abc”, “xyz”, “....”];
stud.push(“a”, “b”);
• Sorting an Array element:
Example: stud.sort();
• Combining an array elements into a string:
Example: let txt = stud.join(“and”);
• Changing Elements of an array:
Example: const index=1;
const newValue=20;
Unit-2 Array, Function and String
• Array Example:
<!DOCTYPE html>
<html>
<body>
<h1>Javascript Arrays</h1>
<script>
var sports= [“Cricket”, “Football”, “Hockey”];
document.write(“Array is=” +sports);
var fruits= [“Banana”, “Orange”, “Apple”, “Mango”];
str=fruits.toString();
document.write(“Array to String=” +str);
len=fruits.length;
document.write(“Length of Fruits Array=” +len);
</script>
</body>
Unit-2 Array, Function and String

• 2.2 Function: defining a function, writing a function, adding an


arguments, scope of variables and arguments:
Example:
function fun(a,b){
return a+b;
}
let sum=fun(10,20);
document.write(result);
Unit-2 Array, Function and String

• 2.3 Calling a function: Calling a function with or without an argument


Example:stud.name();
Example: stud.name(a);
• Return a value from a function :
Example: document.getElementById(“demo”).innerHTML =
myFunction(“John”);
function myFunction(name){
return “Hello” + name;
}
Unit-2 Array, Function and String
<!DOCTYPE html>
<html>
<body>
<h1> JavaScript Functions</h1>
<script>
function fun(a,b){
return a*b;
}
c=fun(3,4);
document.write(c);
</script>
Unit-2 Array, Function and String

• 2.4 String: Manipulate a String


let len = txt.length;
let txt = “HELLO”;
• Retrieving a character from given position:
let char = txt.charAt(0);
let char = txt.charCodeAt(0);
• Joinning a string:
Example: document.getElementById(“demo”).innerHTML= “Hello” +
“welcome”;
Unit-2 Array, Function and String

• Get position of character in a string :


text.indexOf (“welcome”);
• Deviding text:
let text= “How are you”;
const mArray=text.split(“ ”);
• Copying substring:
let text= “Hello world”;
let subStr= text.substring(1,3);
Unit-2 Array, Function and String
• Changing the case of String:
UpperCase:
let txt1= “Hello JS”;
let txt2= txt1.toUpperCase()
LowerCase:
let txt2= txt1.toLowerCase()
fromCharCode() :
Converts unicode values to string.
let txt= String.fromCharCode(72,69,76,76,79);
document.write(txt);

You might also like