ItsJayKee commited on
Commit
0cb4699
·
verified ·
1 Parent(s): 0270f27

manually add the snippets to the code, to make it work in my Visual Studio Code

Browse files
Files changed (1) hide show
  1. script.js +115 -100
script.js CHANGED
@@ -5,97 +5,133 @@ const codeSnippets = {
5
  `<!DOCTYPE html>
6
  <html lang="en">
7
  <head>
8
- <meta charset="UTF-8">
9
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
10
- <title>My Portfolio</title>
11
- <link rel="stylesheet" href="styles.css">
12
  </head>
13
  <body>
14
- <header>
 
 
 
 
 
 
15
  <nav>
16
- <ul>
17
- <li><a href="#home">Home</a></li>
18
- <li><a href="#projects">Projects</a></li>
19
- <li><a href="#contact">Contact</a></li>
20
  </ul>
21
  </nav>
22
  </header>
23
- <main>
24
- <section id="home">
25
- <h1>Welcome to My Portfolio</h1>
26
- <p>I build amazing web experiences</p>
27
- </section>
28
- </main>
29
- <footer>
30
- <p>&copy; ${new Date().getFullYear()}</p>
31
- </footer>
32
- </body>
33
- </html>`
34
- ],
 
 
 
 
35
  javascript: [
36
- `class User {
37
- constructor(name, email) {
38
- this.name = name;
39
- this.email = email;
40
- this.score = 0;
41
- }
42
 
43
- login() {
44
- console.log(this.name, 'just logged in');
45
- return this;
46
- }
 
 
 
47
 
48
- logout() {
49
- console.log(this.name, 'just logged out');
50
- return this;
 
51
  }
52
 
53
- updateScore() {
54
- this.score++;
55
- console.log(this.name, 'score is now', this.score);
56
- return this;
57
  }
58
  }
59
 
60
- const user1 = new User('Alice', 'alice@example.com');
61
- user1.login().updateScore().updateScore().logout();`
62
- ],
 
 
 
 
 
 
 
 
 
 
 
63
  css: [
64
- `.card-container {
65
- display: grid;
66
- grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
67
- gap: 2rem;
68
- padding: 2rem;
69
  }
70
 
71
- .card {
72
- background: white;
73
- border-radius: 8px;
74
- box-shadow: 0 4px 6px rgba(0,0,0,0.1);
75
- transition: transform 0.3s ease;
76
  }
77
 
78
- .card:hover {
79
- transform: translateY(-5px);
 
 
 
 
 
 
 
 
80
  }
81
 
82
- .card img {
83
- width: 100%;
84
- height: 200px;
85
- object-fit: cover;
86
- border-radius: 8px 8px 0 0;
87
  }
88
 
89
- .card-content {
90
- padding: 1.5rem;
 
 
 
 
 
 
91
  }
92
 
93
- @media (max-width: 768px) {
94
- .card-container {
95
- grid-template-columns: 1fr;
96
- }
 
 
 
 
 
 
 
97
  }`
98
- ]
99
  };
100
  // Get all snippets as one array for "all languages" option
101
  function getAllSnippets() {
@@ -255,45 +291,24 @@ function endGame(isCompleted = false) {
255
  saveResults(language, wpm, accuracy, timeTaken);
256
  }
257
  }
258
-
259
- // Save results to database
260
  async function saveResults(language, wpm, accuracy, timeTaken) {
261
- try {
262
- const response = await fetch('db.php', {
263
- method: 'POST',
264
- headers: {
265
- 'Content-Type': 'application/json',
266
- },
267
- body: JSON.stringify({
268
- language,
269
- wpm,
270
- accuracy,
271
- time: timeTaken
272
- })
273
- });
274
-
275
- const data = await response.json();
276
- if (!data.success) {
277
- console.error('Failed to save results:', data.error);
278
- }
279
- } catch (error) {
280
- console.error('Error saving results:', error);
281
- }
282
  }
283
 
284
- // Fetch leaderboard data
285
  async function fetchLeaderboard() {
286
- try {
287
- const response = await fetch('db.php');
288
- const data = await response.json();
289
- if (data.success) {
290
- return data.data;
291
- }
292
- return [];
293
- } catch (error) {
294
- console.error('Error fetching leaderboard:', error);
295
- return [];
296
- }
297
  }
298
  // Event listeners
299
  inputField.addEventListener('input', updateDisplay);
 
5
  `<!DOCTYPE html>
6
  <html lang="en">
7
  <head>
8
+ <title>Document</title>
9
+ <link rel="stylesheet" href="style.css">
 
 
10
  </head>
11
  <body>
12
+ <h1>Hello World</h1>
13
+ <script src="script.js"></script>
14
+ </body>
15
+ </html>`,
16
+
17
+ `<div class="container">
18
+ <header class="header">
19
  <nav>
20
+ <ul class="nav-list">
21
+ <li><a href="/">Home</a></li>
22
+ <li><a href="/about">About</a></li>
 
23
  </ul>
24
  </nav>
25
  </header>
26
+ <main id="main-content"></main>
27
+ <footer>&copy; ${new Date().getFullYear()}</footer>
28
+ </div>`,
29
+
30
+ `<form id="login-form">
31
+ <div class="form-group">
32
+ <label for="email">Email</label>
33
+ <input type="email" id="email" required>
34
+ </div>
35
+ <div class="form-group">
36
+ <label for="password">Password</label>
37
+ <input type="password" id="password" required>
38
+ </div>
39
+ <button type="submit">Login</button>
40
+ </form>`
41
+ ],
42
  javascript: [
43
+ `function calculateTotal(items) {
44
+ return items.reduce((total, item) => {
45
+ return total + (item.price * item.quantity);
46
+ }, 0);
47
+ }
 
48
 
49
+ const cart = [
50
+ { name: 'Shirt', price: 25, quantity: 2 },
51
+ { name: 'Pants', price: 40, quantity: 1 }
52
+ ];
53
+
54
+ const total = calculateTotal(cart);
55
+ console.log('Total:', total);`,
56
 
57
+ `class Person {
58
+ constructor(name, age) {
59
+ this.name = name;
60
+ this.age = age;
61
  }
62
 
63
+ greet() {
64
+ console.log(\`Hello, my name is \${this.name}\`);
 
 
65
  }
66
  }
67
 
68
+ const person1 = new Person('Alice', 30);
69
+ person1.greet();`,
70
+
71
+ `const fetchData = async () => {
72
+ try {
73
+ const response = await fetch('api/data');
74
+ const data = await response.json();
75
+ return data;
76
+ } catch (error) {
77
+ console.error('Error:', error);
78
+ return null;
79
+ }
80
+ };`
81
+ ],
82
  css: [
83
+ `.container {
84
+ max-width: 1200px;
85
+ margin: 0 auto;
86
+ padding: 0 20px;
 
87
  }
88
 
89
+ .header {
90
+ background: #333;
91
+ color: white;
92
+ padding: 1rem;
 
93
  }
94
 
95
+ .nav-list {
96
+ display: flex;
97
+ gap: 1rem;
98
+ list-style: none;
99
+ }`,
100
+
101
+ `body {
102
+ font-family: 'Arial', sans-serif;
103
+ line-height: 1.6;
104
+ color: #333;
105
  }
106
 
107
+ h1, h2, h3 {
108
+ color: #222;
109
+ margin-bottom: 1rem;
 
 
110
  }
111
 
112
+ a {
113
+ color: #0066cc;
114
+ text-decoration: none;
115
+ }`,
116
+
117
+ `@keyframes fadeIn {
118
+ from { opacity: 0; }
119
+ to { opacity: 1; }
120
  }
121
 
122
+ .modal {
123
+ position: fixed;
124
+ top: 0;
125
+ left: 0;
126
+ width: 100%;
127
+ height: 100%;
128
+ background: rgba(0,0,0,0.5);
129
+ display: flex;
130
+ justify-content: center;
131
+ align-items: center;
132
+ animation: fadeIn 0.3s ease;
133
  }`
134
+ ]
135
  };
136
  // Get all snippets as one array for "all languages" option
137
  function getAllSnippets() {
 
291
  saveResults(language, wpm, accuracy, timeTaken);
292
  }
293
  }
294
+ // Mock save results function for local testing
 
295
  async function saveResults(language, wpm, accuracy, timeTaken) {
296
+ console.log('Results would be saved:', {
297
+ language,
298
+ wpm,
299
+ accuracy,
300
+ time: timeTaken
301
+ });
302
+ return { success: true };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  }
304
 
305
+ // Mock leaderboard data for local testing
306
  async function fetchLeaderboard() {
307
+ return [
308
+ { language: 'javascript', wpm: 85, accuracy: 98, time_taken: 120, created_at: new Date() },
309
+ { language: 'html', wpm: 75, accuracy: 95, time_taken: 180, created_at: new Date() },
310
+ { language: 'css', wpm: 65, accuracy: 92, time_taken: 150, created_at: new Date() }
311
+ ];
 
 
 
 
 
 
312
  }
313
  // Event listeners
314
  inputField.addEventListener('input', updateDisplay);