-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
191 lines (180 loc) · 6.41 KB
/
index.html
File metadata and controls
191 lines (180 loc) · 6.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
<!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">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,200;1,300;1,400;1,500;1,600;1,700;1,800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./style.css">
<script src="./rainbow-custom.min.js"></script>
<title>JS-Exercises : CABerlin</title>
</head>
<body>
<main>
<div class="top-container">
<div class="logo"></div>
<div class="bar"></div>
<div class="title">
<h1>JS-Exercises</h1>
</div>
<div class="bar"></div>
<div class="flex-container">
<h2>Writing expressions with variables</h2>
<div class="bar"></div>
<ul class="grid-container">
<li>
<p>1 : I'm <span id="myName"></span></p>
<pre><code data-language="javascript">
let myName = "Ale";
document.getElementById("myName").innerHTML = myName;
console.log("Ex 1: "+myName);
</code></pre>
<pre><code data-language="html">
<p>I'm <span id="myName"></span></p>
</code></pre>
</li>
<li>
<p>2 : My age is <span id="age"></span></p>
<pre><code data-language="javascript">
let age = 36;
document.getElementById("age").innerHTML = age;
console.log("Ex 2: "+age);
</code></pre>
<pre><code data-language="html">
<p>My age is <span id="age"></span></p>
</code></pre>
</li>
<li>
<p>3 : Age diff <span id="ageDiff"></span></p>
<pre><code data-language="javascript">
let juliaAge = 1;
let ageDiff = juliaAge - age;
document.getElementById("ageDiff").innerHTML=ageDiff;
console.log("Ex 3: "+ageDiff);
</code></pre>
<pre><code data-language="html">
<p>Age diff <span id="ageDiff"></span></p>
</code></pre>
</li>
</ul>
</div>
<div class="flex-container">
<div class="bar"></div>
<h2>Writing code with conditionals</h2>
<div class="bar"></div>
<ul class="grid-container">
<li>
<p>4 : You are <span id="number21"></span></p>
<pre><code data-language="javascript">
let number21 = 21;
if (age > number21) {
document.getElementById("number21").innerHTML="older than "+number21;
console.log("Ex 4: You are older than "+number21);
} else {
document.getElementById("number21").innerHTML="not older than "+ number21;
console.log("Ex 4: You are not older than "+number21);
}
</code></pre>
<pre><code data-language="html">
<p>You are <span id="number21"></span></p>
</code></pre>
</li>
<li>
<p>5 : <span id="compareJulia"></span></p>
<pre><code data-language="javascript">
if (juliaAge == age) {
document.getElementById("compareJulia").innerHTML="You have the same age as Julia"
console.log("Ex 5: You have the same age as Julia");
} else if (juliaAge > age) {
document.getElementById("compareJulia").innerHTML="Julia is older than you"
console.log("Ex 5: Julia is older than you");
} else if (juliaAge < age ) {
document.getElementById("compareJulia").innerHTML="Julia is younger than you"
console.log("Ex 5: Julia is younger than you");
}
</code></pre>
<pre><code data-language="html">
<p><span id="compareJulia"></span></p>
</code></pre>
</li>
</ul>
</div>
<div class="flex-container">
<div class="bar"></div>
<h2>Sorting an Array</h2>
<div class="bar"></div>
<ul class="grid-container">
<li>
<p>1 : Alphabetically: <span id="sortArr1"></span></p>
<p>1 : First element: <span id="sortArr2"></span></p>
<p>1 : Last using .at(-1): <span id="sortArr3"></span></p>
<p>1 : Last using .slice(-1): <span id="sortArr4"></span></p>
<p>1 : For loop: <span id="sortArr5"></span></p>
<pre><code data-language="javascript">
const quokkas = [
"Alejandro",
"Jess",
"Arno",
"John",
"Marta",
"Karolina",
"Angelina",
"Raul",
"Ottavia"
]
let sizeQuokkas = quokkas.length;
//Sort the array alphabetically and reverse
console.log("+ Alphabetically: "+quokkas.sort());
document.getElementById("sortArr1").innerHTML=quokkas;
//console.log(quokkas.reverse());
//Print the first element of the array in the console
console.log("+ First element: "+quokkas[0]);
document.getElementById("sortArr2").innerHTML=quokkas[0];
//Print the last element of the array in the console.
let lastQuokkas = quokkas.at(-1)
console.log("+ Last using .at(-1): "+lastQuokkas);
document.getElementById("sortArr3").innerHTML=lastQuokkas;
console.log("+ Last using .slice(-1): "+quokkas.slice(-1));
document.getElementById("sortArr4").innerHTML=quokkas.slice(-1);
//Print all the elements of the array in the console (use a "for" loop)
console.log("-------------------");
for (let i = 0; i < quokkas.length; i++) {
console.log("+ Print all with for loop (Pos "+i+"): "+quokkas[i]);
document.getElementById("sortArr5").innerHTML=quokkas.slice(-1);
}
</code></pre>
<pre><code data-language="html">
<p>You are <span id="number21"></span></p>
</code></pre>
</li>
<li>
<p>2 : <span id="compareJulia"></span></p>
<pre><code data-language="javascript"></code></pre>
<pre><code data-language="html">
<p><span id="compareJulia"></span></p>
</code></pre>
</li>
</ul>
</div>
</div>
<h2>My Favorite Bands</h2>
<ul id="band-list"></ul>
<style>
table {width: 500px; margin: 0 auto;}
table, td {
border: 1px solid black;
font-size: 10px;
padding: 5px;
background:white;
color: black;
}
</style>
<h2>My Multi Table</h2>
<table id="myTable">
</table>
</main>
<script src="./main.js"></script>
</body>
</html>