-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTML FIle
More file actions
299 lines (215 loc) · 8.12 KB
/
HTML FIle
File metadata and controls
299 lines (215 loc) · 8.12 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
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>
Task 1.2P
</title>
<link rel="stylesheet" type="text/css" href="StyleSheet1.css" />
<style>
body {
background-color: white;
}
h1 {
color: black;
text-align: center;
font-size: 40px;
}
h2{
color: black;
text-align: center;
font-size: 30px;
}
h3 {
font-family: Verdana;
font-size: 20px;
text-align: left;
color: cornflowerblue;
}
</style>
</head>
<body>
<!--Main-content section from external css file-->
<section id="main-content">
<h1>JavaScript Concepts</h1>
<h2>This webpage implements various JavaScript Concepts</h2>
<h3>String Methods</h3>
<p>The length of the string "Test" is:</p>
<p id="demo1"></p>
<script>
let text1 = "Test";
document.getElementById("demo1").innerHTML = text1.length;
</script>
<hr />
<p>Use the button to test the replace string method:</p>
<button onclick="replaceFunction()">Button</button>
<p id="demo2">Test</p>
<script>
function replaceFunction() {
let text2 = document.getElementById("demo2").innerHTML;
document.getElementById("demo2").innerHTML =
text2.replace("Test", "Success");
}
</script>
<hr />
<p>Using replaceAll to replace "C/cats" with "D/dogs"</p>
<p id="demo3"></p>
<script>
let text3 = "I love cats. Cats are very easy to love. Cats are very popular."
text3 = text3.replaceAll("Cats", "Dogs");
text3 = text3.replaceAll("cats", "dogs");
document.getElementById("demo3").innerHTML = text3;
</script>
<hr />
<button onclick="toUpperCaseFunction()">To Upper Case</button>
<button onclick="toLowerCaseFunction()">To Lower Case</button>
<p id="demo4">TeSt</p>
<script>
function toUpperCaseFunction() {
let text4 = document.getElementById("demo4").innerHTML;
document.getElementById("demo4").innerHTML =
text4.toUpperCase();
}
function toLowerCaseFunction() {
let text4 = document.getElementById("demo4").innerHTML;
document.getElementById("demo4").innerHTML =
text4.toLowerCase();
}
</script>
<h3>Number Methods</h3>
<p>The toString() method converts a number to a string.</p>
<p id="demo5"></p>
<script>
let x = 123456;
document.getElementById("demo5").innerHTML =
x.toString();
</script>
<hr />
<p>The toFixed() method rounds a number to a given number of digits.</p>
<p>In this case we will round to 2 decimal places.</p>
<p id="demo6"></p>
<script>
let y = 9.656;
document.getElementById("demo6").innerHTML =
y.toFixed(2);
</script>
<hr />
<p>The isInteger() method returns true if the argument is an integer.</p>
<p>Otherwise it returns false.</p>
<p>In this case we have tested numbers 10 and 10.5</p>
<p id="demo7"></p>
<script>
document.getElementById("demo7").innerHTML =
Number.isInteger(10) + "<br>" + Number.isInteger(10.5);
</script>
<hr />
<p>The toPrecision() method returns a string, with a number written with a specified length:</p>
<p>In this case we have specified length 4.</p>
<p id="demo8"></p>
<script>
let z = 9.656;
document.getElementById("demo8").innerHTML =
z.toPrecision(4);
</script>
<hr />
<p>The valueOf() method returns a number as a number:</p>
<p>In this case we are returning "100 + 23"</p>
<p id="demo9"></p>
<script>
document.getElementById("demo9").innerHTML =
(100 + 23).valueOf();
</script>
<h3>Array Methods</h3>
<p>Returning the length of an array</p>
<p id="demo10"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let size = fruits.length;
document.getElementById("demo10").innerHTML = size;
</script>
<hr />
<p>Returning an array as a string that is separated by commas:</p>
<p id="demo11"></p>
<script>
const fruits1 = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo11").innerHTML = fruits1.toString();
</script>
<hr />
<p>Romving the last element from an array using the pop() method.</p>
<p id="demo12"></p>
<p id="demo13"></p>
<script>
const fruits2 = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo12").innerHTML = fruits2;
fruits2.pop();
document.getElementById("demo13").innerHTML = fruits2;
</script>
<hr />
<p>Using the push() method to add new element kiwi to the end of the array</p>
<p id="demo14"></p>
<p id="demo15"></p>
<script>
const fruits3 = [1, 2, 3, 4];
document.getElementById("demo14").innerHTML = fruits3;
fruits3.push("Kiwi");
document.getElementById("demo15").innerHTML = fruits3;
</script>
<hr />
<p>Using the shift() method to remove and return the first element of any array then shift all remaining elements down.</p>
<p id="demo16"></p>
<p id="demo17"></p>
<script>
const fruits4 = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo16").innerHTML = fruits4;
fruits4.shift();
document.getElementById("demo17").innerHTML = fruits4;
</script>
<h3>Date Methods</h3>
<p>Create a new date object with the current date and time:</p>
<p id="demo18"></p>
<script>
const d = new Date();
document.getElementById("demo18").innerHTML = d;
</script>
<hr />
<p>A date object can be created with a specified date and time:</p>
<p id="demo19"></p>
<script>
const a = new Date("October 13, 2014 11:13:00");
document.getElementById("demo19").innerHTML = a;
</script>
<hr />
<p>Using new Date with different number of inputs.</p>
<p>For example, 6 numbers specify year, month, day, hour, minute and second.</p>
<p>This can be used from 7 numbers which adds milliseconds to the example above, down to 2 numbers which is year and month.</p>
<p id="demo20"></p>
<p id="demo22"></p>
<script>
const s = new Date(2018, 11, 24, 10, 33, 30);
document.getElementById("demo20").innerHTML = s;
const t = new Date(2018, 11);
document.getElementById("demo22").innerHTML = t;
</script>
<hr />
<p>Two digit years will be interpreted as 19xx:</p>
<p>also to note, JavaScript counts months from 0 - 11 and any inputs larger than max amount of months/days rolls over to the next year/month. </p>
<p id="demo21"></p>
<script>
const p = new Date(99, 11, 24);
document.getElementById("demo21").innerHTML = p;
</script>
<h3>Function Methods</h3>
<p>Multiplication Function with inputs 4 and 3.</p>
<p id="demo23"></p>
<script>
let f = multiplicationFunction(4, 3);
document.getElementById("demo23").innerHTML = f;
function multiplicationFunction(a, b) {
return a * b;
}
</script>
<hr />
<p style="color: darkslategrey;"></p>
</section>
</body>
</html>