-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.html
More file actions
327 lines (291 loc) · 10.5 KB
/
java.html
File metadata and controls
327 lines (291 loc) · 10.5 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width= , initial-scale=1.0">
<title>Document</title>
</head>
c <style>
* {
margin: 0;
padding: 0;
}
.container {
border: 2px solid red;
background: cyan;
margin: 3px 0px;
padding: 5px;
}
.background {
background-color: black;
}
.text {
color: white;
}
.power {
background: black;
border: 2px solid red;
color: white;
padding: 9px;
}
</style>
<body>
<h1>this new start of javascript</h1>
<div id="firstcontainer" class="container">
<button id="click" onclick="clicked()">click me</button>
<!-- <button id="click" onclick="document.getElementById('demo').innerHTML=Date()">click me</button>
<p id="demo"></p> -->
<!-- <button id="click" onclick="this.innerHTML=Date()">click me</button> -->
</div>
<div id="asifa" class="container">
<button id="fatima" onclick="clickedd()">to know</button>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Temporibus, laborum!</p>
</div>
<div id="dil" class="container">
<p>power this society is never change and i will be keep learning</p>
</div>
<script>
//1. ways to print in javascript
// alert("me")
// document.write("This is new world")
//2. javascript console api
// console.log("Hellow world")
// console.warn("This is warning")
// console.error("This is error")
// 3. what are variables
//what is variables- containers to store the values
var num1 = 34;
var num2 = 36;
// console.log(num1 + num2);
// 4. data type in javascript
// number
var number1 = 344;
var number2 = 36.4;
// string
var str1 = "This is a string";
var str2 = "This is a new string"
// objects
var marks = {
faizan: 34,
fahad: 56,
}
// console.log(marks)
// bolean
var a = true;
var b = false;
// console.log(a ,b);
//at a very high level. there are two types of data types in java script
// 1. primitive data types: null undefine number string bolean symbol
//2. reference data types: objects and arrays
var arr = [1, 2, 3, 4, 5]
// console.log(arr)
//operators in java scripts
// arthematic operator
var a = 34;
var b = 10;
// console.log("This value of a + b", a+b);
// console.log("This value of a - b", a-b);
// console.log("This value of a * b", a*b);
// console.log("This value of a / b", a/b);
//assigment operators
var c = b;
c -= 2; //c=c-2
// c += 2; c=c+2
// c *= 2; c=c*2
// c /= 2; c=c/2
// console.log(c)
// comparison operators
// var x = 34;
// var y = 36;
// console.log(x==y);
// console.log(c >= y);
// console.log(x <= y);
// logical operators (&&)
// console.log(true && true)
// console.log(false && true)
// console.log(true && false)
// logical operators or(||)
// console.log(true || false)
// console.log(false || false)
// logical not
// console.log(!false)
// console.log(!true)
// function in javascript
function avg(a, b) {
c = (a + b) / 2;
return c;
}
c1 = avg(400, 650);
c2 = avg(350, 650);
// console.log(c1);
// console.log(c2);
//if and else function
var age = 8;
// if (age > 9){
// console.log('This is not a kid');
// }
// else{
// console.log("Your are a kids");
// }
age = 31; //var can be rewrite
// if else ledder
// if(age < 10 ){
// console.log("you are kid");
// }
// else if(age < 18){
// console.log("you are young");
// }
// else if(age < 30){
// console.log("You are adult");
// }
// else{
// console.log("your are old")
// }
var arr = [1, 2, 3, 4, 5, 6];
for (var i = 0; i < arr.length; i++) {
// if(i == 3){
// // break;
// // continue
// }
// console.log(arr[i])
}
// arr.forEach(function(element){
// console.log(element)
// }
// )
// while loop
// let j = 0;
// while (j < arr.length) {
// console.log(arr[j]);
// j++;
// }
// do{
// console.log(arr[j]);
// j++;
// }while(j<arr.length);
let myArr = ["new", "power", 34, "null", "anime"];
// myArr.push("power");
// myArr.shift();
// myArr.pop();
// const newline = myArr.unshift("power");
// console.log(newline);
// console.log(myArr);
let myString = "This is a new string";
// console.log(myString.length)
// console.log(myString.indexOf("new"))
// d = myString.replace("This", "We");
// d = d.replace("new", "old")
// console.log(d, myString);
// let myDate = new Date();
// console.log(myDate.getTime());
// console.log(myDate.getSeconds());
// console.log(myDate.getDay());
// dom ,amanipilation
let elem = document.getElementById("click")
// console.log(elem);
let elemClass = document.getElementsByClassName("container");
// console.log(elemClass);
//targeting // elemClass[0].style.background = "yellow"
//adding class in elements
elemClass[0].classList.add("background")
elemClass[0].classList.add("text")
// removing class in elements
// elemClass[0].classList.remove("background")
// finding any elements inner html
// console.log(elemClass[0].innerHTML);
// console.log(elemClass[0].innerText);
tn = document.getElementsByTagName("div")
console.log(tn);
//aappenchild
createdElement = document.createElement('p');
createdElement.innerText = "this is new dream";
tn[0].appendChild(createdElement);
dilshad = document.createElement('p');
dilshad.innerText = "This is new form new build";
tn[1].appendChild(dilshad);
//remove child
// tn[1].removeChild(dilshad);
zeeshan = document.createElement("p")
zeeshan.innerText = "This is new line"
tn[2].appendChild(zeeshan);
//replacechild
zeeshan2 = document.createElement('b')
zeeshan2.innerText = "This is a bold";
tn[2].replaceChild(zeeshan2, zeeshan);
//selecting querry
// sel = document.querySelector('.container')
// console.log(sel)
// sel = document.querySelectorAll(".container")
// console.log(sel)
// sel = document.querySelector(".container")
// sel.querySelector("p").style.backgroundColor = 'green'
// sel = document.querySelectorAll('p')
// for(i=0;i<sel.length;i++){
// sel[i].style.backgroundColor = 'red';
// }
// event in javascript
// function clicked(){
// console.log("This is clicked")
// }
// function clickedd(){
// console.log("MY NAME IS DILSHAD TRYINNG TO LEARN")
// }
// firstcontainer.addEventListener('click', function(){
// document.querySelectorAll(".container")[1].innerHTML = "<b> we changed into bold"
// console.log("This was clicked")
// })
// asifa.addEventListener('click', function(){
// document.querySelectorAll(".container")[2].innerHTML = "<b> we jumped to third"
// console.log("mouseout will go in and shows")
// })
// dil.addEventListener("mouseout", function(){
// console.log("mouseout will go out and shows")
// }
// firstcontainer.addEventListener('mouseup', function(){
// console.log("This is clicked")
// })
// firstcontainer.addEventListener("mousedown", function(){
// console.log("This is down ")
// })
// )
// let prevHTML = document.querySelectorAll('.container')[1].innerHTML;
// firstcontainer.addEventListener('mouseup', function(){
// document.querySelectorAll('.container')[1].innerHTML = prevHTML;
// console.log("mousup after clicking will shows")
// })
// firstcontainer.addEventListener('mousedown', function(){
// document.querySelectorAll(".container")[1].innerHTML = "<b> we jumped to third </b>"
// console.log("mousedown after releasing clicking will shows")
// })
//arrow function
// 1. normal function
// function summ(a,b){
// return a + b;
// }
//2. arrow function
summ = (a, b) => {
return a + b;
}
// settimeout
logkaro = () => {
document.querySelectorAll('.container')[1].innerHTML = "<b>This is set timeout</b>"
console.log("this is setTimeout")
}
// to cancel settimeout/setinterval we use cleaarTimeout(clr)/clerInterval(clr)
//only one execcuted
// setTimeout(logkaro, 2000)
//infinnite executed
// CLR = setInterval(logkaro, 2000);
// json in javascript
// stringify convert object into json string
// obj = {name:"Dilshad",length:1,a:{"the":"that"}}
// jso = JSON.stringify(obj)
// console.log(typeof jso)
// console.log(jso)
// parse convert json string into javascript object
// Parsed = JSON.parse('{name:"Dilshad",length:1,a:{"the":"that"}}');
// console.log(Parsed);
</script>
</body>
</html>