-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
313 lines (215 loc) · 6.5 KB
/
index.html
File metadata and controls
313 lines (215 loc) · 6.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Variables</h1>
<h2>I - calculate</h2>
<p>In this example, x, y, and z are variables.</p>
<p id="demo"></p>
<script>
var x = 5;
var y = 6;
var z = x + y;
document.getElementById("demo").innerHTML =
"The value of z is: " + z;
</script>
<p id="demo"></p>
<p id="division"></p>
<script>
var p = 10;
var i = 2;
var q = p / i;
document.getElementById("division").innerHTML =
"The value of q is: " + q;
</script>
<h2>II - concatenate sentence</h2>
<p>The result of adding "Julia" + " " + "Julia":</p>
<p id="concatenate"></p>
<script>
var x = "Julia" + " " + "Julia";
document.getElementById("concatenate").innerHTML = x;
</script>
<h2>III - VAT</h2>
<p id="vat"></p>
<h4>VAT Calculator</h4><br> Amount($): <input type="text" id="amount" name="txt_amount">
<br><br>
<button onclick="calculateVAT(amount.value)">Calculate Total Amount</button>
<script>
function calculateVAT(x) {
if (x.length == 0) {
alert("Numbers cannot be blank");
return;
}
if (isNaN(x)) {
alert("Value entered is not numeric");
return;
}
var result = parseInt(x) * 0.21;
alert("Multiplication: " + result);
}
</script>
<h1>Conditions</h1>
Conditions
<h4>II - maximum</h4>
<script>
var array = [267, 306, 108];
var largest = Math.max.apply(Math, array); // 306
</script>
<h4>IV - day’s number</h4>
<p id="days"></p>
<script>
var day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
document.getElementById("days").innerHTML = "Today is " + day;
</script>
<h1>Loops</h1>
<script>
for I = 1 until n do {
output($I)
}
// Let's drink coffee
integer nbr_coffee = n
boolean has_coffee = true
while ($has_coffee == true)
do {
drink_coffee()
$nbr_coffee = $nbr_coffee - 1
if ($nbr_coffee == 0) then {
$has_coffee = false
}
}
</script>
<p id="loop2"></p>
<script>
var text = ""
var i = 0;
do {
text += "<br>The number is " + i;
i++;
}
while (i < 10);
document.getElementById("loop2").innerHTML = text;
</script>
<h1>Arrays</h1>
<h2>I print an array</h2>
<p id="array"></p>
<script>
var cats = ["Saab", "Miau", "Lucy"];
document.getElementById("array").innerHTML = cats;
</script>
<h2>II - maximum</h2>
<p>Write an algorithm which receives an array of integers and prints its maximum.</p>
<p id="max"></p>
<script>
document.getElementById("max").innerHTML =
Math.max(0, 150, 30, 20, 500, -200);
</script>
<h2>III - minimum</h2>
<p>Write an algorithm which receives an array of integers and prints its minimum.</p>
<p id="min"></p>
<script>
document.getElementById("min").innerHTML =
Math.min(0, 150, 30, 20, 500, -200);
</script>
<h2>IV - minimum position</h2>
<p>Write an algorithm which receives an array of integers and prints the position of its minimum.
</p>
<p>The lowest number is <span id="position"></span>.</p>
<script>
var points = [40, 100, 1, 5, 25, 10];
points.sort(function (a, b) {
return a - b
});
document.getElementById("position").innerHTML = points[0];
</script>
<h1>Functions</h1>
<h1>Trial by pseudo code</h1>
<h2>I - list of random numbers</h2>
<p>Write a function which returns an array of n random numbers, n being the only received parameter.</p>
function randomArray(n) { <br>
let array = [] <br>
for (let i = 0; i < n; i++) { <br>
array.push(Math.floor(Math.random() * Math.floor(1000))) <br>
} <br>
return array <br>
} <br>
<h2>II - translate</h2>
<p>
The main goal of pseudo code is to write down the logic behind an algorithm, so that you can easily translate it
into human speech or code.
Given the algorithm below
- with your word explain its purpose
- translate it into Python and Javascript
function in_array(element,list_elements) { <br>
boolean exist = false <br>
for I = 0 until length($list_elements) do { <br>
if $element == $list_elements[I] then { <br>
$exist = true <br>
} <br>
} <br>
return $exist <br>
} <br>
</p>
<br>
<p>This function has two arguments: element and list_elements. The boolean exist is defined as false. The function
will look for the "element" in the array till this will be found.
Once the element is found, we are receiving the answer "true". Is element is not found, the function returns
"false".
</p>
<p>Variant 1</p>
function inArray(element, list_elements) { <br>
let exist = false <br>
list_elements.array.forEach(element => { <br>
if (item == element) exist = true <br>
}) <br>
console.log(exist); <br>
} <br>
<p>Variant 2</p>
function inArray(element, list_elements) {<br>
let exist = false <br>
for (let i = 0; i < list_elements.length; i++) { <br>
return exist <br>
}<br>
<p>III - sort an array</p>
<h2>JavaScript Array Sort</h2>
<p>Click the button to sort the array in ascending order.</p>
<button onclick="myFunction()">Try it</button>
<p id="sort"></p>
<script>
var points = [40, 100, 1, 5, 25, 10, 11, 22, 56, 89];
document.getElementById("sort").innerHTML = points;
function myFunction() {
points.sort(function (a, b) {
return a - b
});
document.getElementById("sort").innerHTML = points;
}
</script>
<script src="script.js"></script>
</body>
</html>