Skip to content

Commit 7a964cc

Browse files
authored
chore: Add all remaining project files
This commit completes the project structure, adding the final scripts, styles, and assets to the 'Constellation Lab' repository. The universe is now ready to be explored.
1 parent 08e31e4 commit 7a964cc

File tree

6 files changed

+564
-0
lines changed

6 files changed

+564
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

assets/logo.svg

Lines changed: 18 additions & 0 deletions
Loading

assets/sounds/click.mp3

1.04 KB
Binary file not shown.

index.html

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<meta name="description" content="Mastering JavaScript Fundamentals — variables, conditionals, functions, loops, and DOM." />
7+
<title>Constellation Lab — Mastering JavaScript Fundamentals</title>
8+
<link rel="icon" href="assets/logo.svg" type="image/svg+xml">
9+
<link rel="stylesheet" href="style.css" />
10+
</head>
11+
<body>
12+
<a class="skip-link" href="#main">Skip to main content</a>
13+
<header class="site-header">
14+
<div class="container header-inner">
15+
<img src="assets/logo.svg" alt="" width="160" height="40" />
16+
<nav aria-label="Primary">
17+
<ul class="nav-list">
18+
<li><a href="#basics">Basics</a></li>
19+
<li><a href="#functions">Functions</a></li>
20+
<li><a href="#loops">Loops</a></li>
21+
<li><a href="#dom">DOM</a></li>
22+
</ul>
23+
</nav>
24+
<button id="themeBtn" class="btn primary">Toggle Theme</button>
25+
</div>
26+
</header>
27+
<main id="main" class="container">
28+
<section id="basics" aria-labelledby="basics-title" class="panel">
29+
<h1 id="basics-title">Part 1 — JavaScript Basics</h1>
30+
<p>Enter your name and age; we will categorize and greet you.</p>
31+
<form id="userForm">
32+
<div class="grid">
33+
<label>Name
34+
<input id="nameInput" type="text" placeholder="Your Name" />
35+
</label>
36+
<label>Age
37+
<input id="ageInput" type="number" placeholder="e.g., 25" />
38+
</label>
39+
<button id="submitBtn" type="submit" class="btn primary">Submit</button>
40+
</div>
41+
<p id="greet" class="output" aria-live="polite"></p>
42+
</form>
43+
</section>
44+
45+
<section id="functions" aria-labelledby="functions-title" class="panel">
46+
<h2 id="functions-title">Part 2 — Functions</h2>
47+
<p>Calculate your age based on your birth year.</p>
48+
<div class="grid">
49+
<label>Birth Year
50+
<input id="birthYearInput" type="number" placeholder="e.g., 1990" />
51+
</label>
52+
<button id="birthYearBtn" class="btn primary">Calculate</button>
53+
</div>
54+
<p id="ageOut" class="output" aria-live="polite"></p>
55+
</section>
56+
57+
<section id="loops" aria-labelledby="loops-title" class="panel">
58+
<h2 id="loops-title">Part 3 — Loops</h2>
59+
<p>Generated with loops: a countdown and a starred list.</p>
60+
<div class="grid">
61+
<button id="countdownBtn" class="btn primary">Start 5 → 0</button>
62+
<button id="starsBtn" class="btn primary">Generate 6 Stars</button>
63+
</div>
64+
<ul id="listOut" class="list"></ul>
65+
</section>
66+
67+
<section id="dom" aria-labelledby="dom-title" class="panel">
68+
<h2 id="dom-title">Part 4 — DOM Interactions</h2>
69+
<ul>
70+
<li>Listening to clicks (buttons above)</li>
71+
<li>Changing text content and classes</li>
72+
<li>Creating and appending elements dynamically</li>
73+
</ul>
74+
<div class="grid" id="domSection">
75+
<button id="domBtn1" class="btn primary">Change Color</button>
76+
<button id="domBtn2" class="btn primary">Toggle Paragraph</button>
77+
</div>
78+
<p id="toggleText" class="output">This paragraph's visibility is controlled by the Toggle Paragraph button above.</p>
79+
<p class="muted">Explore the console to see logged steps.</p>
80+
</section>
81+
</main>
82+
<footer class="site-footer" id="contact" role="contentinfo">
83+
<div class="container footer-grid">
84+
<section aria-label="Contact">
85+
<h3>Contact</h3>
86+
<ul>
87+
<li>Augusto Mate</li>
88+
<li><a href="mailto:mate.augusto.mz@gmail.com">mate.augusto.mz@gmail.com</a></li>
89+
</ul>
90+
</section>
91+
92+
<section class="footer-mission" aria-label="Project Mission">
93+
<p>
94+
We build constellations from lines of code, where every pixel is a star and every function, a new universe.
95+
</p>
96+
</section>
97+
98+
<section aria-label="Links">
99+
<h3>Links</h3>
100+
<ul>
101+
<li><a href="#basics">Basics</a></li>
102+
<li><a href="#functions">Functions</a></li>
103+
<li><a href="#loops">Loops</a></li>
104+
<li><a href="#dom">DOM</a></li>
105+
</ul>
106+
</section>
107+
</div>
108+
<p class="legal">© <span id="year"></span> 2025 Constellation Lab</p>
109+
</footer>
110+
111+
<audio id="clickSound" src="assets/sounds/click.mp3" preload="auto"></audio>
112+
113+
<script src="script.js"></script>
114+
</body>
115+
</html>

script.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// ============================================================================
2+
// Constellation Lab
3+
// (with sound functionality)
4+
// ============================================================================
5+
6+
// Utility function to play a click sound.
7+
function playClickSound() {
8+
const sound = document.getElementById('clickSound');
9+
if (sound) {
10+
sound.currentTime = 0;
11+
sound.play();
12+
}
13+
}
14+
15+
// Get the current year once the page is fully loaded.
16+
let currentYear;
17+
document.addEventListener('DOMContentLoaded', () => {
18+
currentYear = new Date().getFullYear();
19+
});
20+
21+
// Part 1: JavaScript Basics
22+
const form = document.getElementById('userForm');
23+
const nameInput = document.getElementById('nameInput');
24+
const ageInput = document.getElementById('ageInput');
25+
const greetOut = document.getElementById('greet');
26+
27+
form.addEventListener('submit', (e) => {
28+
e.preventDefault();
29+
playClickSound();
30+
31+
const name = String(nameInput.value).trim();
32+
const age = Number(ageInput.value);
33+
34+
let group;
35+
if (age < 13) group = 'child';
36+
else if (age < 18) group = 'teen';
37+
else if (age < 60) group = 'adult';
38+
else group = 'senior';
39+
40+
greetOut.textContent = name
41+
? `Hello, ${formatName(name)} — you are categorized as: ${group}.`
42+
: 'Please provide your name.';
43+
44+
console.log({ name, age, group });
45+
});
46+
47+
// Part 2: Functions
48+
function formatName(name) {
49+
if (!name) return '';
50+
return name[0].toUpperCase() + name.slice(1).toLowerCase();
51+
}
52+
53+
function calculateAge(birthYear) {
54+
return currentYear - birthYear;
55+
}
56+
57+
const birthYearInput = document.getElementById('birthYearInput');
58+
const birthYearBtn = document.getElementById('birthYearBtn');
59+
const ageOut = document.getElementById('ageOut');
60+
61+
birthYearBtn.addEventListener('click', () => {
62+
playClickSound();
63+
const birthYear = Number(birthYearInput.value);
64+
if (!birthYear || birthYear > currentYear) {
65+
ageOut.textContent = 'Please enter a valid birth year.';
66+
} else {
67+
const age = calculateAge(birthYear);
68+
ageOut.textContent = `Your age is: ${age} years old.`;
69+
console.log(`Age calculated: ${age}`);
70+
}
71+
});
72+
73+
// Part 3: Loops
74+
const listOut = document.getElementById('listOut');
75+
76+
document.getElementById('countdownBtn').addEventListener('click', () => {
77+
playClickSound();
78+
listOut.innerHTML = '';
79+
listOut.classList.add('left-align');
80+
listOut.classList.remove('right-align');
81+
let n = 5;
82+
while (n >= 0) {
83+
const li = document.createElement('li');
84+
li.textContent = `Countdown: ${n}`;
85+
listOut.appendChild(li);
86+
n--;
87+
}
88+
});
89+
90+
document.getElementById('starsBtn').addEventListener('click', () => {
91+
playClickSound();
92+
listOut.innerHTML = '';
93+
listOut.classList.add('right-align');
94+
listOut.classList.remove('left-align');
95+
for (let i = 1; i <= 6; i++) {
96+
const li = document.createElement('li');
97+
li.textContent = '★'.repeat(i);
98+
listOut.appendChild(li);
99+
}
100+
});
101+
102+
// Part 4: DOM Manipulation
103+
const domBtn1 = document.getElementById('domBtn1');
104+
const domBtn2 = document.getElementById('domBtn2');
105+
// We now get the whole section element by its ID
106+
const domSection = document.getElementById('dom');
107+
const toggleText = document.getElementById('toggleText');
108+
109+
domBtn1.addEventListener('click', () => {
110+
playClickSound();
111+
// Toggle the new class on the section, not the inner div
112+
domSection.classList.toggle('panel--colored');
113+
console.log('Panel background color toggled.');
114+
});
115+
116+
domBtn2.addEventListener('click', () => {
117+
playClickSound();
118+
toggleText.classList.toggle('hidden');
119+
const isHidden = toggleText.classList.contains('hidden');
120+
console.log(`Paragraph visible: ${!isHidden}`);
121+
});
122+
123+
// Part 5: Theme Switcher
124+
const themeBtn = document.getElementById('themeBtn');
125+
themeBtn.addEventListener('click', () => {
126+
playClickSound();
127+
document.body.classList.toggle('light-theme');
128+
console.log('Theme toggled. Check the body element class.');
129+
});

0 commit comments

Comments
 (0)