-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
772 lines (723 loc) · 31.2 KB
/
index.html
File metadata and controls
772 lines (723 loc) · 31.2 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Master Relations - Complete Learning Platform</title>
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { useState } = React;
// Lucide React Icons as SVG components
const ChevronRight = () => (
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
);
const ChevronLeft = () => (
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<polyline points="15 18 9 12 15 6"></polyline>
</svg>
);
const BookOpen = () => (
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"></path>
<path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"></path>
</svg>
);
const CheckCircle = ({ size = 24, className = "" }) => (
<svg width={size} height={size} className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
<polyline points="22 4 12 14.01 9 11.01"></polyline>
</svg>
);
const RotateCcw = ({ size = 24 }) => (
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<polyline points="1 4 1 10 7 10"></polyline>
<path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"></path>
</svg>
);
const Lightbulb = ({ className = "" }) => (
<svg width="24" height="24" className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"></path>
<path d="M9 18h6"></path>
<path d="M10 22h4"></path>
</svg>
);
const Award = ({ className = "" }) => (
<svg width="24" height="24" className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<circle cx="12" cy="8" r="7"></circle>
<polyline points="8.21 13.89 7 23 12 20 17 23 15.79 13.88"></polyline>
</svg>
);
function RelationsLearningPlatform() {
const [currentLevel, setCurrentLevel] = useState(0);
const [selectedExample, setSelectedExample] = useState('example1');
const [showAnswer, setShowAnswer] = useState(false);
const [userAnswer, setUserAnswer] = useState('');
const [score, setScore] = useState(0);
const [completed, setCompleted] = useState({});
const levels = [
{
id: 'intro',
title: '1. What is a RELATION?',
icon: '🔗',
content: {
explanation: `A RELATION is a connection between elements of two sets.
Think of it like a friendship network:
• Set A = People in your class
• Set B = People in another class
• The relation = "is friends with"
KEY POINT: A relation pairs elements from Set A with elements from Set B.`,
examples: {
example1: {
name: 'Simple Number Pairs',
setA: ['1', '2', '3', '4'],
setB: ['2', '4', '6', '8'],
pairs: [
{ from: '1', to: '2' },
{ from: '2', to: '4' },
{ from: '3', to: '6' },
{ from: '4', to: '8' }
],
rule: 'y = 2x (double the input)',
orderedPairs: '{(1,2), (2,4), (3,6), (4,8)}',
isFunction: true
},
example2: {
name: 'One-to-Many',
setA: ['A', 'B', 'C'],
setB: ['1', '2', '3', '4'],
pairs: [
{ from: 'A', to: '1' },
{ from: 'A', to: '2' },
{ from: 'B', to: '3' },
{ from: 'C', to: '4' }
],
rule: 'A connects to multiple outputs',
orderedPairs: '{(A,1), (A,2), (B,3), (C,4)}',
isFunction: false
},
example3: {
name: 'Many-to-One',
setA: ['Cat', 'Dog', 'Bird', 'Fish'],
setB: ['Pet', 'Wild'],
pairs: [
{ from: 'Cat', to: 'Pet' },
{ from: 'Dog', to: 'Pet' },
{ from: 'Bird', to: 'Pet' },
{ from: 'Fish', to: 'Pet' }
],
rule: 'Multiple inputs → same output',
orderedPairs: '{(Cat,Pet), (Dog,Pet), (Bird,Pet), (Fish,Pet)}',
isFunction: true
}
},
question: 'Can one element from Set A connect to multiple elements in Set B?',
answer: 'YES! That is allowed in relations.',
practice: 'Look at "One-to-Many" example. Is this a valid relation?'
}
},
{
id: 'diagrams',
title: '2. PICTORIAL DIAGRAMS',
icon: '📊',
content: {
explanation: `There are 3 ways to show relations visually:
1. ARROW DIAGRAM (Mapping Diagram)
• Two ovals/circles for sets
• Arrows show connections
2. ORDERED PAIRS
• Written as (input, output)
• Example: {(1,2), (3,4)}
3. TABLE
• Two columns: Input | Output
• Easy to read and organize`,
examples: {
example1: {
name: 'Arrow Diagram Example',
setA: ['x', 'y', 'z'],
setB: ['1', '2', '3'],
pairs: [
{ from: 'x', to: '1' },
{ from: 'y', to: '2' },
{ from: 'z', to: '3' }
],
orderedPairs: '{(x,1), (y,2), (z,3)}',
table: 'Input: x→1, y→2, z→3',
isFunction: true
},
example2: {
name: 'Multiple Representations',
setA: ['2', '4', '6'],
setB: ['1', '2', '3', '4'],
pairs: [
{ from: '2', to: '1' },
{ from: '4', to: '2' },
{ from: '6', to: '3' }
],
orderedPairs: '{(2,1), (4,2), (6,3)}',
table: 'Each even number divides to its half',
isFunction: true
},
example3: {
name: 'With Disconnected Elements',
setA: ['a', 'b', 'c', 'd'],
setB: ['1', '2', '3'],
pairs: [
{ from: 'a', to: '1' },
{ from: 'c', to: '2' }
],
orderedPairs: '{(a,1), (c,2)}',
table: 'b and d have no connections',
isFunction: true
}
},
question: 'Which representation is easiest to check if something is a function?',
answer: 'Arrow diagram! You can visually see if any element has 2+ arrows.',
practice: 'Convert the ordered pairs {(a,1), (b,2), (a,3)} to an arrow diagram in your mind.'
}
},
{
id: 'domain',
title: '3. DOMAIN',
icon: '📥',
content: {
explanation: `DOMAIN = All the INPUT values that actually have connections
Think of it as:
• What you PUT INTO the machine
• The starting values that map to something
• All x-values that have arrows
IMPORTANT: Domain only includes elements that connect to something!
Example: If Set A = {1,2,3,4} but only 1,2,3 have arrows:
✅ Domain = {1, 2, 3}
❌ NOT {1,2,3,4}`,
examples: {
example1: {
name: 'Finding Domain',
setA: ['1', '2', '3', '4', '5'],
setB: ['a', 'b', 'c'],
pairs: [
{ from: '1', to: 'a' },
{ from: '3', to: 'b' },
{ from: '5', to: 'c' }
],
orderedPairs: '{(1,a), (3,b), (5,c)}',
domain: '{1, 3, 5}',
note: '2 and 4 are NOT in domain - they have no connections!',
isFunction: true
},
example2: {
name: 'Complete Domain',
setA: ['a', 'b', 'c'],
setB: ['1', '2', '3', '4'],
pairs: [
{ from: 'a', to: '1' },
{ from: 'b', to: '2' },
{ from: 'c', to: '3' }
],
orderedPairs: '{(a,1), (b,2), (c,3)}',
domain: '{a, b, c}',
note: 'All elements of Set A are used - complete domain!',
isFunction: true
},
example3: {
name: 'Repeated Input',
setA: ['x', 'y', 'z'],
setB: ['1', '2', '3', '4'],
pairs: [
{ from: 'x', to: '1' },
{ from: 'x', to: '2' },
{ from: 'y', to: '3' }
],
orderedPairs: '{(x,1), (x,2), (y,3)}',
domain: '{x, y}',
note: 'x appears twice but counts only once in domain! z not included.',
isFunction: false
}
},
question: 'If Set A = {1,2,3} and pairs are {(1,x), (1,y)}, what is the domain?',
answer: '{1} - Only 1 has connections, even though it connects twice!',
practice: 'Domain only includes elements that connect, regardless of how many times.'
}
},
{
id: 'codomain',
title: '4. CO-DOMAIN',
icon: '📤',
content: {
explanation: `CO-DOMAIN = ALL of Set B (whether used or not)
KEY DIFFERENCE from Range:
• Co-domain = ENTIRE Set B (all possibilities)
• Range = Only values that are ACTUALLY used
Example:
Set B = {1, 2, 3, 4, 5}
If only 1, 2, 3 are connected:
• Co-domain = {1, 2, 3, 4, 5} ← All of Set B
• Range = {1, 2, 3} ← Only used values
Analogy:
Co-domain = All snacks in vending machine
Range = Only snacks that were bought`,
examples: {
example1: {
name: 'Co-domain vs Range',
setA: ['x', 'y'],
setB: ['1', '2', '3', '4', '5'],
pairs: [
{ from: 'x', to: '2' },
{ from: 'y', to: '4' }
],
orderedPairs: '{(x,2), (y,4)}',
codomain: '{1, 2, 3, 4, 5}',
range: '{2, 4}',
note: 'Co-domain includes 1,3,5 even though unused!',
isFunction: true
},
example2: {
name: 'When They Match',
setA: ['a', 'b', 'c'],
setB: ['1', '2', '3'],
pairs: [
{ from: 'a', to: '1' },
{ from: 'b', to: '2' },
{ from: 'c', to: '3' }
],
orderedPairs: '{(a,1), (b,2), (c,3)}',
codomain: '{1, 2, 3}',
range: '{1, 2, 3}',
note: 'Co-domain = Range when ALL values are used!',
isFunction: true
},
example3: {
name: 'Large Co-domain',
setA: ['A', 'B'],
setB: ['P', 'Q', 'R', 'S', 'T', 'U'],
pairs: [
{ from: 'A', to: 'Q' },
{ from: 'B', to: 'T' }
],
orderedPairs: '{(A,Q), (B,T)}',
codomain: '{P, Q, R, S, T, U}',
range: '{Q, T}',
note: 'Co-domain much larger than range - most values unused!',
isFunction: true
}
},
question: 'Is co-domain always bigger than or equal to range?',
answer: 'YES! Range is always a subset of (or equal to) co-domain.',
practice: 'Co-domain = entire Set B. Range = values actually reached.'
}
},
{
id: 'range',
title: '5. RANGE',
icon: '🎯',
content: {
explanation: `RANGE = OUTPUT values that are ACTUALLY USED
How to find range:
1. Look at all the arrows
2. See which elements in Set B have arrows TO them
3. Those elements = the range
IMPORTANT RULES:
• Range ⊆ Co-domain (subset or equal)
• Element with NO arrows → NOT in range
• Element with multiple arrows → still counts ONCE
• Range includes only unique output values`,
examples: {
example1: {
name: 'Finding Range',
setA: ['1', '2', '3', '4'],
setB: ['a', 'b', 'c', 'd', 'e'],
pairs: [
{ from: '1', to: 'a' },
{ from: '2', to: 'c' },
{ from: '3', to: 'c' },
{ from: '4', to: 'e' }
],
orderedPairs: '{(1,a), (2,c), (3,c), (4,e)}',
domain: '{1, 2, 3, 4}',
codomain: '{a, b, c, d, e}',
range: '{a, c, e}',
note: 'b and d NOT in range - no arrows point to them! c used twice.',
isFunction: true
},
example2: {
name: 'Range with Repeats',
setA: ['Red', 'Blue', 'Green', 'Yellow'],
setB: ['Warm', 'Cool'],
pairs: [
{ from: 'Red', to: 'Warm' },
{ from: 'Yellow', to: 'Warm' },
{ from: 'Blue', to: 'Cool' },
{ from: 'Green', to: 'Cool' }
],
orderedPairs: '{(Red,Warm), (Yellow,Warm), (Blue,Cool), (Green,Cool)}',
domain: '{Red, Blue, Green, Yellow}',
codomain: '{Warm, Cool}',
range: '{Warm, Cool}',
note: 'Range = Co-domain! Both values used. Many-to-one relation.',
isFunction: true
},
example3: {
name: 'Single Element Range',
setA: ['1', '2', '3'],
setB: ['a', 'b', 'c'],
pairs: [
{ from: '1', to: 'b' },
{ from: '2', to: 'b' },
{ from: '3', to: 'b' }
],
orderedPairs: '{(1,b), (2,b), (3,b)}',
domain: '{1, 2, 3}',
codomain: '{a, b, c}',
range: '{b}',
note: 'Range has only ONE element even though used 3 times!',
isFunction: true
}
},
question: 'In pairs {(1,a), (2,a), (3,a)}, what is the range?',
answer: '{a} - Only one element, even though multiple inputs map to it!',
practice: 'Count unique OUTPUT values that have at least one arrow.'
}
}
];
const currentLevelData = levels[currentLevel];
const currentExample = currentLevelData.content.examples[selectedExample];
const checkAnswer = () => {
setShowAnswer(true);
const userLower = userAnswer.toLowerCase().trim();
const answerLower = currentLevelData.content.answer.toLowerCase();
if ((userLower.includes('yes') && answerLower.includes('yes')) ||
(userLower.includes('{1}') && answerLower.includes('{1}')) ||
(userLower.includes('{a}') && answerLower.includes('{a}')) ||
(userLower.includes('arrow') && answerLower.includes('arrow')) ||
userLower.includes('subset') || userLower.includes('equal')) {
setScore(score + 1);
setCompleted({...completed, [currentLevelData.id]: true});
}
};
const nextLevel = () => {
if (currentLevel < levels.length - 1) {
setCurrentLevel(currentLevel + 1);
setShowAnswer(false);
setUserAnswer('');
setSelectedExample('example1');
}
};
const prevLevel = () => {
if (currentLevel > 0) {
setCurrentLevel(currentLevel - 1);
setShowAnswer(false);
setUserAnswer('');
setSelectedExample('example1');
}
};
return (
<div className="min-h-screen bg-gradient-to-br from-indigo-500 via-purple-500 to-pink-500 p-4">
<div className="max-w-7xl mx-auto">
{/* Header */}
<div className="text-center mb-6">
<h1 className="text-5xl font-bold text-white mb-2">
📚 Master Relations - Complete Guide
</h1>
<p className="text-xl text-white">Learn Every Concept Step by Step</p>
<div className="mt-4 bg-white rounded-full px-6 py-2 inline-flex items-center gap-2">
<Award className="text-yellow-500" />
<span className="font-bold">Score: {score}</span>
<span className="text-gray-500">| Progress: {currentLevel + 1}/{levels.length}</span>
</div>
</div>
{/* Progress Bar */}
<div className="bg-white rounded-full h-4 mb-6 overflow-hidden shadow-lg">
<div
className="bg-gradient-to-r from-green-400 to-blue-500 h-full transition-all duration-500"
style={{ width: `${((currentLevel + 1) / levels.length) * 100}%` }}
/>
</div>
{/* Topic Navigation */}
<div className="grid grid-cols-5 gap-2 mb-6">
{levels.map((level, idx) => (
<button
key={level.id}
onClick={() => {
setCurrentLevel(idx);
setShowAnswer(false);
setUserAnswer('');
setSelectedExample('example1');
}}
className={`p-3 rounded-xl font-bold transition-all ${
currentLevel === idx
? 'bg-yellow-300 text-purple-900 scale-105 shadow-xl'
: completed[level.id]
? 'bg-green-400 text-white'
: 'bg-white text-gray-700 hover:bg-gray-100'
}`}
>
<div className="text-2xl mb-1">{level.icon}</div>
<div className="text-xs">{level.title.split('.')[1]?.trim()}</div>
{completed[level.id] && <CheckCircle size={16} className="mx-auto mt-1" />}
</button>
))}
</div>
{/* Main Content */}
<div className="grid md:grid-cols-2 gap-6">
{/* Left Panel - Explanation */}
<div className="bg-white rounded-3xl p-6 shadow-2xl">
<div className="flex items-center gap-3 mb-4">
<div className="text-4xl">{currentLevelData.icon}</div>
<h2 className="text-2xl font-bold text-gray-800">
{currentLevelData.title}
</h2>
</div>
<div className="bg-blue-50 rounded-xl p-4 mb-4 border-2 border-blue-200">
<div className="flex items-start gap-2">
<BookOpen className="text-blue-600 mt-1 flex-shrink-0" />
<pre className="text-gray-800 whitespace-pre-wrap font-sans text-sm">
{currentLevelData.content.explanation}
</pre>
</div>
</div>
{/* Example Selector */}
<div className="mb-4">
<h3 className="font-bold text-gray-700 mb-2">Choose Example:</h3>
<div className="grid grid-cols-3 gap-2">
{Object.entries(currentLevelData.content.examples).map(([key, ex]) => (
<button
key={key}
onClick={() => setSelectedExample(key)}
className={`p-2 rounded-lg font-semibold text-xs transition-all ${
selectedExample === key
? 'bg-purple-500 text-white shadow-lg'
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'
}`}
>
{ex.name}
</button>
))}
</div>
</div>
{/* Current Example Details */}
<div className="bg-yellow-50 rounded-xl p-4 border-2 border-yellow-300">
<h4 className="font-bold text-yellow-900 mb-2">
📝 {currentExample.name}
</h4>
<div className="space-y-1 text-sm">
<p><strong>Ordered Pairs:</strong> {currentExample.orderedPairs}</p>
{currentExample.domain && <p><strong>Domain:</strong> {currentExample.domain}</p>}
{currentExample.codomain && <p><strong>Co-domain:</strong> {currentExample.codomain}</p>}
{currentExample.range && <p><strong>Range:</strong> {currentExample.range}</p>}
{currentExample.rule && <p><strong>Rule:</strong> {currentExample.rule}</p>}
{currentExample.note && (
<p className="text-yellow-800 italic mt-2 text-xs">💡 {currentExample.note}</p>
)}
</div>
</div>
</div>
{/* Right Panel - Visualization */}
<div className="bg-white rounded-3xl p-6 shadow-2xl">
<h3 className="text-xl font-bold text-center text-gray-800 mb-6">
Arrow Diagram (Mapping)
</h3>
<div className="relative flex justify-between items-start gap-4 mb-6" style={{ minHeight: '400px' }}>
{/* Set A */}
<div className="flex-1">
<div className="bg-blue-100 rounded-xl p-4 border-4 border-blue-300">
<h4 className="text-center font-bold text-blue-900 mb-3 text-sm">
SET A<br/>(Input)
</h4>
<div className="space-y-2">
{currentExample.setA.map((item, idx) => (
<div
key={idx}
className="bg-white rounded-lg p-2 shadow-md text-center font-bold text-gray-800 border-2 border-blue-400 text-sm"
>
{item}
</div>
))}
</div>
</div>
</div>
{/* Arrows */}
<div className="absolute inset-0 pointer-events-none">
<svg className="w-full h-full">
{currentExample.pairs.map((pair, idx) => {
const fromIdx = currentExample.setA.indexOf(pair.from);
const toIdx = currentExample.setB.indexOf(pair.to);
const colors = ['#ef4444', '#3b82f6', '#10b981', '#f59e0b', '#8b5cf6', '#ec4899'];
const color = colors[idx % colors.length];
// Calculate exact positions - center of each box
// Box height is roughly 40px (p-2 + text), starting at ~90px from top
const boxHeight = 42;
const startY = 112; // Adjusted to align with center of first box
const spacing = boxHeight + 8; // 8px gap between boxes
const y1 = startY + (fromIdx * spacing);
const y2 = startY + (toIdx * spacing);
return (
<g key={idx}>
<line
x1="37%"
y1={y1}
x2="63%"
y2={y2}
stroke={color}
strokeWidth="3"
markerEnd="url(#arrowhead)"
/>
</g>
);
})}
<defs>
<marker
id="arrowhead"
markerWidth="10"
markerHeight="10"
refX="9"
refY="3"
orient="auto"
>
<polygon points="0 0, 10 3, 0 6" fill="#666" />
</marker>
</defs>
</svg>
</div>
{/* Set B */}
<div className="flex-1">
<div className="bg-green-100 rounded-xl p-4 border-4 border-green-300">
<h4 className="text-center font-bold text-green-900 mb-3 text-sm">
SET B<br/>(Output)
</h4>
<div className="space-y-2">
{currentExample.setB.map((item, idx) => (
<div
key={idx}
className="bg-white rounded-lg p-2 shadow-md text-center font-bold text-gray-800 border-2 border-green-400 text-sm"
>
{item}
</div>
))}
</div>
</div>
</div>
</div>
{/* Practice Question */}
<div className="bg-purple-50 rounded-xl p-4 border-2 border-purple-300">
<div className="flex items-start gap-2 mb-3">
<Lightbulb className="text-purple-600 flex-shrink-0 mt-1" />
<div>
<h4 className="font-bold text-purple-900 mb-2">Practice Question:</h4>
<p className="text-gray-800 text-sm">{currentLevelData.content.question}</p>
</div>
</div>
{!showAnswer ? (
<div>
<input
type="text"
value={userAnswer}
onChange={(e) => setUserAnswer(e.target.value)}
placeholder="Type your answer..."
className="w-full p-3 border-2 border-purple-300 rounded-lg mb-2 text-sm"
/>
<button
onClick={checkAnswer}
className="w-full bg-purple-500 text-white py-2 rounded-lg font-bold hover:bg-purple-600"
>
Check Answer
</button>
</div>
) : (
<div className="bg-green-100 rounded-lg p-3 border-2 border-green-400">
<div className="flex items-center gap-2 mb-2">
<CheckCircle className="text-green-600" />
<span className="font-bold text-green-800">Answer:</span>
</div>
<p className="text-gray-800 text-sm">{currentLevelData.content.answer}</p>
<p className="text-sm text-gray-600 mt-2 italic">
{currentLevelData.content.practice}
</p>
</div>
)}
</div>
</div>
</div>
{/* Navigation */}
<div className="flex justify-between items-center mt-6">
<button
onClick={prevLevel}
disabled={currentLevel === 0}
className={`flex items-center gap-2 px-6 py-3 rounded-xl font-bold ${
currentLevel === 0
? 'bg-gray-300 text-gray-500 cursor-not-allowed'
: 'bg-white text-purple-600 hover:bg-gray-100'
}`}
>
<ChevronLeft /> Previous Topic
</button>
<button
onClick={() => {
setShowAnswer(false);
setUserAnswer('');
}}
className="flex items-center gap-2 px-6 py-3 rounded-xl font-bold bg-yellow-400 text-gray-800 hover:bg-yellow-500"
>
<RotateCcw size={20} /> Reset Question
</button>
<button
onClick={nextLevel}
disabled={currentLevel === levels.length - 1}
className={`flex items-center gap-2 px-6 py-3 rounded-xl font-bold ${
currentLevel === levels.length - 1
? 'bg-gray-300 text-gray-500 cursor-not-allowed'
: 'bg-white text-purple-600 hover:bg-gray-100'
}`}
>
Next Topic <ChevronRight />
</button>
</div>
{/* Summary Box */}
<div className="mt-8 bg-white rounded-2xl p-6 shadow-2xl">
<h3 className="text-2xl font-bold text-center text-gray-800 mb-4">
🎓 Quick Reference Guide
</h3>
<div className="grid md:grid-cols-3 gap-4">
<div className="bg-blue-50 rounded-xl p-4 border-2 border-blue-200">
<h4 className="font-bold text-blue-900 mb-2">📥 Domain</h4>
<p className="text-sm text-gray-700">All INPUT elements that have connections from Set A</p>
</div>
<div className="bg-purple-50 rounded-xl p-4 border-2 border-purple-200">
<h4 className="font-bold text-purple-900 mb-2">📤 Co-domain</h4>
<p className="text-sm text-gray-700">ENTIRE Set B (all possible outputs)</p>
</div>
<div className="bg-green-50 rounded-xl p-4 border-2 border-green-200">
<h4 className="font-bold text-green-900 mb-2">🎯 Range</h4>
<p className="text-sm text-gray-700">OUTPUT elements that are ACTUALLY USED from Set B</p>
</div>
</div>
<div className="mt-4 bg-yellow-50 rounded-xl p-4 border-2 border-yellow-300 text-center">
<p className="font-bold text-yellow-900">
💡 Remember: Domain ⊆ Set A | Range ⊆ Co-domain | Co-domain = Set B
</p>
</div>
</div>
</div>
</div>
);
}
ReactDOM.render(<RelationsLearningPlatform />, document.getElementById('root'));
</script>
</body>
</html>