-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJavaScript_tutorial.html
More file actions
347 lines (308 loc) · 15.1 KB
/
JavaScript_tutorial.html
File metadata and controls
347 lines (308 loc) · 15.1 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Fundamentals</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
/* General Styles */
body {
font-family: 'Arial', sans-serif;
background: #f4f4f4;
margin: 0;
padding: 0;
transition: 0.3s;
}
.dark-mode {
background: #222;
color: #fff;
}
/* Header */
header {
background: #2c3e50;
color: #fff;
padding: 10px 20px;
display: flex;
justify-content: space-between;
align-items: center;
position: sticky;
top: 0;
z-index: 1000;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.logo {
font-size: 24px;
font-weight: bold;
color: #fff;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
align-items: center;
}
nav ul li {
margin-left: 25px;
}
nav ul li a {
color: #fff;
text-decoration: none;
font-weight: bold;
font-size: 16px;
transition: color 0.3s ease;
}
nav ul li a:hover {
color: #ff6f61;
}
.hamburger {
display: none;
font-size: 24px;
cursor: pointer;
}
/* Main Content */
.header {
text-align: center;
padding: 20px;
background: #fff;
margin: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.header h3 {
font-size: 28px;
margin-bottom: 10px;
}
.search-box {
padding: 10px;
width: 80%;
max-width: 400px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
.toggle-btn {
background: #008CBA;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
transition: background 0.3s ease;
}
.toggle-btn:hover {
background: #005f73;
}
/* Sections */
.section {
background: #333;
color: #fff;
padding: 15px;
margin: 10px 20px;
border-radius: 10px;
cursor: pointer;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.section:hover {
transform: translateY(-5px);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}
.content {
display: none;
padding: 15px;
background: #fff;
border-left: 5px solid #333;
color: black;
margin: 10px 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.dark-mode .content {
background: #444;
color: white;
border-left: 5px solid #008CBA;
}
textarea {
width: 100%;
height: 100px;
font-family: monospace;
margin-top: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 14px;
}
.copy-btn, .run-btn {
background: #008CBA;
color: white;
padding: 8px 16px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-right: 10px;
transition: background 0.3s ease;
}
.copy-btn:hover, .run-btn:hover {
background: #005f73;
}
/* Footer */
footer {
background: #1a252f;
color: #fff;
text-align: center;
padding: 20px;
margin-top: 20px;
}
footer p {
margin: 0;
}
/* Responsive Design */
@media (max-width: 768px) {
.hamburger {
display: block;
}
nav ul {
display: none;
flex-direction: column;
width: 100%;
background: #2c3e50;
position: absolute;
top: 60px;
left: 0;
}
nav ul.active {
display: flex;
}
nav ul li {
margin: 10px 0;
text-align: center;
}
.header h3 {
font-size: 24px;
}
.search-box {
width: 90%;
}
}
</style>
</head>
<body>
<!-- Header -->
<header>
<div class="logo">Learn Coding</div>
<nav>
<ul class="menu">
<li><a href="#home">Home</a></li>
<li><a href="#tutorials">Tutorials</a></li>
<li><a href="#topics">Topics</a></li>
<li><a href="#testimonials">Testimonials</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div class="hamburger" onclick="toggleMenu()">☰</div>
</nav>
</header>
<!-- Main Content -->
<div class="header">
<h3>📌 JavaScript Tutorial</h3>
<hr/>
<input type="text" id="search" class="search-box" placeholder="🔍 Search topics..." onkeyup="searchTopics()">
<br/>
<button class="toggle-btn" onclick="toggleDarkMode()">🌙 Toggle Dark Mode</button>
</div>
<!-- Sections -->
<div id="topics-container"></div>
<!-- Footer -->
<footer id="contact">
<p>© 2023 Learn Coding. All rights reserved.</p>
</footer>
<script>
const topics = [
["Print in JavaScript", 'Swal.fire("Hello, JavaScript! Now get back to work!");'],
["Variables", 'let drink = "Whiskey"; Swal.fire("Tonight, we are drinking: " + drink);'],
["Functions", 'function flirt() { Swal.fire("Hey there! Are you a JavaScript function? Because you just returned my heart."); } flirt();'],
["Arrays", 'let exes = ["Emily", "Sophie", "Jessica"]; Swal.fire("My list of exes: " + exes.join(", "));'],
["Objects", 'let sugarDaddy = { name: "Mr. Rich", balance: "Unlimited 💸" }; Swal.fire(sugarDaddy.name + " has " + sugarDaddy.balance + " in his bank!");'],
["If-Else Conditions", 'let age = 21;\nif (age >= 18) Swal.fire("You can drink! Cheers! 🍻");\nelse Swal.fire("Sorry kid, stick to juice.");'],
["Loops", 'let tequilaShots = "";\nfor (let i = 1; i <= 5; i++) tequilaShots += "🥃 ";\nSwal.fire("Tequila rounds: " + tequilaShots);'],
["Events", 'document.body.onclick = function() { Swal.fire("Oops! You clicked too much, go touch some grass! 🌿"); };'],
["DOM Manipulation", 'document.body.style.background = "pink"; Swal.fire("We made it spicy! 🌶️");'],
["Template Literals", 'let lover = "Jessica"; Swal.fire(`Dear ${lover}, you still owe me dinner! 😏`);'],
["Arrow Functions", 'const party = (vibe) => Swal.fire(`Tonight’s party mood: ${vibe} 🔥`);\nparty("wild");'],
["SetTimeout & SetInterval", 'setTimeout(() => Swal.fire("Reminder: Flirt responsibly! 😘"), 3000);'],
["Local Storage", 'localStorage.setItem("crush", "Samantha"); Swal.fire("Saved your crush’s name in local storage! 😉");'],
["JSON Handling", 'let secret = { crush: "Samantha", age: 24 };\nSwal.fire("Your secret: " + JSON.stringify(secret));'],
["Async/Await", 'async function dateRequest() {\nSwal.fire("Texting crush... 📲");\nawait new Promise(r => setTimeout(r, 2000));\nSwal.fire("Reply received: Maybe. 😏");\n}\ndateRequest();'],
["Promises", 'new Promise((resolve) => setTimeout(() => resolve("Netflix and chill? 🍿"), 2000)).then(msg => Swal.fire(msg));'],
["Error Handling", 'try { throw new Error("Your ex is calling! Abort! 🚨"); } catch (e) { Swal.fire(e.message); }'],
["Spread & Rest Operators", 'let drinks = ["Beer", "Wine", "Whiskey"];\nlet allDrinks = [...drinks, "Tequila", "Gin"];\nSwal.fire("Tonight’s menu: " + allDrinks);'],
["Map & Filter", 'let numbers = [10, 20, 30, 40, 50];\nlet filtered = numbers.filter(n => n > 25);\nSwal.fire("Big money bets: " + filtered);'],
["Classes", 'class Playboy { constructor(name) { this.name = name; } flirt() { return this.name + " is smooth AF! 😉"; } }\nlet player = new Playboy("James");\nSwal.fire(player.flirt());'],
["Drunk Mode (toLowerCase)", 'let text = "I LOVE JAVASCRIPT!"; Swal.fire(text.toLowerCase());'],
["Horny Filter (includes)", 'let chat = "Hey, wanna grab some coffee?";\nif (chat.includes("coffee")) Swal.fire("☕ Flirt detected!");'],
["Love Calculator (Math.random)", 'let love = Math.floor(Math.random() * 100) + 1;\nSwal.fire(`❤️ Love Score: ${love}%`);'],
["Naughty Confession (Prompt)", 'let confession = prompt("Tell me your darkest secret...");\nSwal.fire(`😏 I know your secret: ${confession}`);'],
["Date Picker (Date object)", 'let date = new Date();\nSwal.fire(`📅 Today is ${date.toDateString()}`);'],
["Flirty Message (Ternary Operator)", 'let hotness = Math.random() > 0.5 ? "🔥 You’re sexy!" : "🥶 Try harder!";\nSwal.fire(hotness);'],
["Drunk Dial Prevention (Confirm)", 'if (!confirm("Are you sure you want to send this drunk text?")) Swal.fire("Phew! Saved from embarrassment!");'],
["Online Dating Score (Object)", 'let user = { looks: 8, humor: 10, intelligence: 6 };\nSwal.fire(`💘 Your Dating Score: ${(user.looks + user.humor + user.intelligence) / 3}`);'],
["Thirst Meter (Switch Case)", 'let thirstLevel = 3;\nlet message = "";\nswitch (thirstLevel) {\n case 1: message = "🥤 Hydrated"; break;\n case 2: message = "🍺 Thirsty"; break;\n case 3: message = "🔥 Desperate"; break;\n default: message = "💀 Dehydrated";\n}\nSwal.fire(message);'],
["OnlyFans Calculator (Map)", 'let earnings = [50, 100, 200, 500];\nlet doubled = earnings.map(e => e * 2);\nSwal.fire(`💸 Your OnlyFans earnings doubled: $${doubled}`);'],
["Pick-Up Line Generator 💘", 'let lines = ["Are you a magician? Because whenever I look at you, everyone else disappears!", "Do you believe in love at first sight, or should I walk by again?", "Is your name Google? Because you have everything I’ve been searching for."]; Swal.fire(lines[Math.floor(Math.random() * lines.length)]);'],
["Meme Magic 🖼️", 'let memes = ["https://i.imgflip.com/30b1gx.jpg", "https://i.imgflip.com/4/1otk96.jpg", "https://i.imgflip.com/1bh8.jpg"]; Swal.fire({ imageUrl: memes[Math.floor(Math.random() * memes.length)], imageWidth: 400, imageHeight: 300, });'],
["Truth or Dare Game 🎭", 'let tod = ["Truth: What’s your weirdest habit?", "Dare: Send a romantic message to your crush!", "Truth: Have you ever stalked someone online?", "Dare: Dance like crazy for 30 seconds!"]; Swal.fire(tod[Math.floor(Math.random() * tod.length)]);'],
["Fake Virus Prank 💀", 'setTimeout(() => Swal.fire("⚠️ System Error: Your computer is hacked!"), 2000); setTimeout(() => Swal.fire("😂 Just kidding!"), 5000);'],
["Girlfriend/Boyfriend Name Picker 😏", 'let names = ["Sophia", "Emma", "Olivia", "Liam", "Noah", "Ethan"]; Swal.fire("Your partner’s name is: " + names[Math.floor(Math.random() * names.length)]);'],
["Love Calculator ❤️", 'let love = Math.floor(Math.random() * 100) + 1; Swal.fire("Your love compatibility is: " + love + "% ❤️");'],
["Random Roast Generator 🔥", 'let roasts = ["You bring everyone so much joy… when you leave the room!", "You have something on your chin… no, the third one down!", "You bring everyone together... when they all agree they don’t like you!"]; Swal.fire(roasts[Math.floor(Math.random() * roasts.length)]);'],
["Drunk Typing Effect 🍻", 'let drunk = "I’m noot drunjk, you arre!".split("").map((c, i) => i % 2 ? c.toUpperCase() : c.toLowerCase()).join(""); Swal.fire(drunk);'],
["Who's Your Daddy? 👀", 'let daddy = ["Elon Musk", "Bill Gates", "Jeff Bezos", "Tony Stark", "Your Wallet"]; Swal.fire("Your daddy is: " + daddy[Math.floor(Math.random() * daddy.length)]);'],
["Strip Game (for fun 🤭)", 'let items = ["Shirt", "Pants", "Socks", "Jacket", "Hat"]; Swal.fire("You lost! Take off your " + items[Math.floor(Math.random() * items.length)] + "! 😈");']
];
const topicsContainer = document.getElementById('topics-container');
topics.forEach((topic, index) => {
topicsContainer.innerHTML += `
<div class="section" onclick="toggleContent('q${index + 1}')">${index + 1}️⃣ ${topic[0]}</div>
<div id="q${index + 1}" class="content">
<textarea id="code${index + 1}">${topic[1]}</textarea><br>
<button class="run-btn" onclick="runCode('code${index + 1}')">Run</button>
<button class="copy-btn" onclick="copyToClipboard('code${index + 1}')">Copy</button>
</div>
`;
});
function toggleContent(id) {
let content = document.getElementById(id);
content.style.display = (content.style.display === "none" || content.style.display === "") ? "block" : "none";
}
function copyToClipboard(codeId) {
let codeElement = document.getElementById(codeId);
codeElement.select();
document.execCommand("copy");
Swal.fire("✅ Code copied!");
}
function runCode(codeId) {
let code = document.getElementById(codeId).value;
try { eval(code); }
catch (error) { Swal.fire("❌ Error: " + error.message); }
}
function toggleDarkMode() {
document.body.classList.toggle("dark-mode");
Swal.fire("🌙 Dark mode " + (document.body.classList.contains("dark-mode") ? "enabled" : "disabled"));
}
function searchTopics() {
let input = document.getElementById("search").value.toLowerCase();
let sections = document.getElementsByClassName("section");
for (let section of sections) {
if (section.textContent.toLowerCase().includes(input)) section.style.display = "";
else section.style.display = "none";
}
}
function toggleMenu() {
const menu = document.querySelector('.menu');
menu.classList.toggle('active');
}
</script>
</body>
</html>