-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7-functions.html
100 lines (77 loc) · 2.93 KB
/
7-functions.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!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>functions in javaScript</title>
</head>
<body>
<script>
//without parameters in functions
// function bioData(){
// console.log("my name is "+ name);
// console.log("my age is "+ age);
// console.log("my city is "+ city);
// }
// let name="saleem Raza"
// let age=18;
// let city="karachi";
// bioData();
//with parameters in function
// function sum(a,b){
// let add=a+b;
// console.log("the sum of two numbers are "+ add);
// }
// sum(5,6);
// sum(7,8);
// with return values in functions
// function percentage(a,b,c,){
// let total=300;
// let per= (a+b+c)/total *100;
// return per
// }
// let p=percentage(75,85,95);
// console.log("the percentage of three numbers are " + p +"%");
// quick assignment compare two numbers and print greater number
// function compare(a,b) {
// if(a>b){
// console.log("the greater number is "+ a);
// console.log("the smallesr number is "+b);
// }
// else{
// console.log("the greater number is "+b);
// console.log("the smallest number is "+a);
// }
// }
// compare(78,89);
// compare(90,100);
// some mostly using string methods and function are :
let name= "saleem";
let friend= "raza"
let cousin=" ali ";
// 1:
console.log(name.length); // it will return the length of the string
//2:
console.log(name.toUpperCase()); // it will convert the string into uppar case
//3:
console.log(name.toLowerCase()); // convert into lower case
//4:
console.log(name.concat(" is a friend of ",friend)); // it will concatnate the string
//5:
console.log(name.slice(2)); // it will print the string which will start from index 2 up to the end of string index
//6:
console.log(name.slice(2,4));// it will print the string which will start form index 2 and end to index 3
//7:
console.log(cousin.trim());
//8:
console.log(cousin.trimEnd());
//9:
console.log(name.replace("saleem","muhammad")); // it will replace the string
//10:
console.log(name.substring(2)); // same work as slice() but the slice() functiion will take negative value also.
//11:
console.log(name.indexOf("m")); // it will print the index of perticular string which we mintion on round bracket of indexOf() function.
</script>
</body>
</html>