This repository was archived by the owner on Dec 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
204 lines (164 loc) · 4.41 KB
/
index.html
File metadata and controls
204 lines (164 loc) · 4.41 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>vanilla js start</title>
<style rel="stylesheet">
body {
text-align: center;
font-family: arial;
font-size: 1rem;
}
li {
list-style: none;
line-height: 2em;
text-align: left;
}
.header {
background: #f4f4f4;
border-bottom: #ccc 3px solid;
padding: 1.1rem;
}
.button {
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.container {
width: 700px;
margin: 2rem auto;
}
</style>
</head>
<body onload="showdate()">
<div class="header">
<h1 id="heading"> learning js </h1>
<p> With hammou kacem amine </p>
</div>
<div class="container">
<!-- <button onclick="doclick()">Click Me</button> -->
<!-- <button onclick="this.innerHTML='you clicked'">Click Me</button> -->
<button onclick="changetext(this)">Click Me</button>
<button onmouseout="cleardate()" onmouseover="showdate()">show date</button>
<h1 id="time"></h1>
<form action="" method="post" name="myForm" onsubmit="return validateForm()">
<div>
<label for="name">First Name</label>
<input type="text" name="FirstName" id="FirstName">
</div>
<br>
<div>
<label for="lastname">LastName</label>
<input type="text" name="LastName" id="LastName">
</div>
<br>
<div>
<label for="bg">background</label>
<select name="background" id="background" onchange="changebg(this)">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<br>
<input type="submit" value="Submit">
</select>
</div>
</form>
</div>
<script>
function validateForm() {
var firstname = document.forms['myForm']['FirstName'].value;
if (firstname == null || firstname == '' || firstname.length < 3) {
alert('first name required');
return false;
}
}
function changebg(x) {
console.log(x.value);
var body = document.querySelector('body');
body.style.backgroundColor = x.value;
}
function cleardate() {
document.getElementById('time').innerHTML = '';
}
function showdate() {
document.getElementById('time').innerHTML = Date();
}
function changetext() {
var heading = document.getElementById('heading');
heading.innerHTML = ' new fucking heading ';
}
//
// function changetext(id) {
// id.innerHTML = 'you clicked';
// }
var colors = new Array('red', 'yellow');
colors.push('purple');
console.log(colors.length);
// alert(colors.sort());
// reverse() etc..
for (var i = 0; i < 10; i++) {
console.log(i);
}
colors.forEach((string) => {
console.log(string);
});
//object literal
var person = {
firstname: 'amine',
lastname: 'hammou',
age: '24',
children: ['ous', 'beasic'],
street: {
city: 'blida',
province: 09,
state: 'algeria'
},
fullname: function () {
return this.children + " " + this.street.city;
}
}
console.log(person.fullname());
// var apple = new object();
// apple.color = 'red';
// apple.shape = 'round';
// apple.describe = function(){
// return 'an apple is the color '+this.color+' and is the shape '+this.shape;
// }
// console.log(apple.describe());
//constructor pattern
function fruit(name, color, shape) {
this.name = name;
this.color = color;
this.shape = shape;
this.describe = () => {
return this.name + ' ' + this.color + ' ' + this.shape;
}
}
var apple = new fruit('apple', 'red', 'round');
console.log(apple);
var melon = new fruit('melon', 'brown', 'rectangle');
console.log(melon.describe());
var users = [{
name: 'amine hammou',
age: 20
},
{
name: 'popo hammou',
age: 50
},
{
name: 'cisco hammou',
age: 2
}
];
console.log(users[0].name);
// events
// function doclick() {
// alert('you are an asshole');
// }
</script>
</body>
</html>