Skip to content

Commit c6a5976

Browse files
committed
Fixed All issues
1 parent 3b793fc commit c6a5976

3 files changed

Lines changed: 208 additions & 3 deletions

File tree

absolute-beginners/full-stack/css/box-model.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Use these for more control:
6464

6565
## 4. The "Box-Sizing" Problem
6666

67-
By default, if you give a box a width of `200px` and then add `20px` of padding, the box actually becomes **240px** wide (200 + 20 \text{ left} + 20 \text{ right}). This often breaks layouts!
67+
By default, if you give a box a width of `200px` and then add `20px` of padding, the box actually becomes **240px** wide (200 + 20 left + 20 right). This often breaks layouts!
6868

6969
### The Fix: `border-box`
7070

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,100 @@
1-
<ComingSoon />
1+
---
2+
title: "Arrays and Objects"
3+
sidebar_label: "4. Arrays & Objects"
4+
sidebar_position: 4
5+
description: "Learn how to store collections of data using Arrays and Objects in JavaScript."
6+
---
7+
8+
So far, we've stored one piece of data in one variable (like `let fruit = "apple"`). But what if you have a list of 100 fruits? Or what if you want to store a "User Profile" with a name, age, and email?
9+
10+
This is where **Arrays** and **Objects** come in.
11+
12+
## 1. Arrays (The Ordered List)
13+
14+
An **Array** is a single variable that holds a list of items in a specific order. You define an array using square brackets `[]`.
15+
16+
```javascript
17+
let fruits = ["Apple", "Banana", "Cherry"];
18+
```
19+
20+
### Accessing Items (Indexing)
21+
In programming, we start counting at **0**.
22+
* `fruits[0]` is "Apple"
23+
* `fruits[1]` is "Banana"
24+
25+
### Common Array Actions:
26+
27+
```javascript
28+
fruits.push("Orange"); // Adds to the end
29+
fruits.pop(); // Removes the last item
30+
console.log(fruits.length); // Tells you how many items are inside (3)
31+
```
32+
33+
## 2. Objects (The Labeled Cabinet)
34+
35+
While Arrays are lists, **Objects** store data in "Key-Value" pairs. Use curly braces `{}` for objects. They are perfect for describing a single thing in detail.
36+
37+
```javascript
38+
const user = {
39+
firstName: "Ajay",
40+
lastName: "Dhangar",
41+
age: 25,
42+
isDeveloper: true
43+
};
44+
```
45+
46+
### Accessing Data:
47+
48+
You use **Dot Notation** to get information out of an object:
49+
50+
```javascript
51+
console.log(user.firstName); // Output: Ajay
52+
console.log(user.age); // Output: 25
53+
```
54+
55+
## 3. Which one should I use?
56+
57+
It can be confusing at first. Use this simple rule:
58+
59+
| Use an **Array** when... | Use an **Object** when... |
60+
| :--- | :--- |
61+
| You have a **list** of similar things. | You want to **describe** one thing. |
62+
| Order matters (1st, 2nd, 3rd). | Order doesn't matter. |
63+
| Example: A list of students. | Example: A single student's profile. |
64+
65+
## 4. Combining Both (The Real World)
66+
67+
In a real application like **CodeHarborHub**, we often have an **Array of Objects**. This is how a list of tutorials or users is actually stored!
68+
69+
```javascript
70+
const courses = [
71+
{ title: "HTML Basics", status: "Completed" },
72+
{ title: "CSS Mastery", status: "In Progress" },
73+
{ title: "JS Logic", status: "Not Started" }
74+
];
75+
76+
// To get the title of the first course:
77+
console.log(courses[0].title); // Output: HTML Basics
78+
```
79+
80+
## Practice: The "My Team" List
81+
82+
Try building this in your `script.js`:
83+
84+
1. Create an **Object** for yourself called `me` with your name and favorite hobby.
85+
2. Create an **Array** called `myTeam` and put your object inside it.
86+
3. Add another object to the array for a friend.
87+
4. Use `console.log` to print the hobby of the second person in your array.
88+
89+
```javascript
90+
const me = { name: "Ajay", hobby: "Cricket" };
91+
const friend = { name: "Rahul", hobby: "Coding" };
92+
93+
const myTeam = [me, friend];
94+
95+
console.log(myTeam[1].hobby); // Output: Coding
96+
```
97+
98+
:::info Const with Arrays/Objects
99+
You'll notice we usually use `const` for Arrays and Objects. This is because even though the *content* inside might change (we add a fruit or update an age), the "cabinet" itself stays the same.
100+
:::
Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,107 @@
1-
<ComingSoon />
1+
---
2+
title: "DOM Manipulation"
3+
sidebar_label: "5. DOM Manipulation"
4+
sidebar_position: 5
5+
description: "Learn how to use JavaScript to change your HTML and CSS on the fly."
6+
---
7+
8+
The **DOM (Document Object Model)** is the map that the browser creates of your HTML. JavaScript uses this map to find, change, add, or delete things on your web page without refreshing it.
9+
10+
Think of the DOM as a **Tree**. Every HTML tag is a branch or a leaf that JavaScript can grab onto.
11+
12+
## 1. Selecting Elements
13+
14+
Before you can change something, you have to "find" it. JavaScript provides several ways to grab elements from your HTML.
15+
16+
| Method | Use case | Example |
17+
| :--- | :--- | :--- |
18+
| `getElementById()` | To find a single, unique element. | `document.getElementById('header')` |
19+
| `querySelector()` | To find the first element that matches a CSS selector. | `document.querySelector('.btn')` |
20+
| `querySelectorAll()` | To find EVERY element that matches. | `document.querySelectorAll('p')` |
21+
22+
## 2. Changing the Content
23+
24+
Once you have grabbed an element, you can change what is inside it.
25+
26+
```javascript
27+
// 1. Find it
28+
const myTitle = document.getElementById('main-title');
29+
30+
// 2. Change it
31+
myTitle.innerText = "Welcome to CodeHarborHub!";
32+
myTitle.style.color = "blue"; // You can even change CSS!
33+
```
34+
35+
## 3. Listening for Events
36+
37+
This is how we make buttons actually *do* things. We use an **Event Listener** to "listen" for user actions like clicks, typing, or scrolling.
38+
39+
```javascript
40+
const btn = document.querySelector('.my-button');
41+
42+
// "When the button is clicked, run this function"
43+
btn.addEventListener('click', () => {
44+
alert("Button was clicked!");
45+
});
46+
```
47+
48+
## 4. Creating New Elements
49+
50+
You aren't stuck with the HTML you started with. You can create brand new elements out of thin air.
51+
52+
```javascript
53+
// 1. Create it
54+
const newPara = document.createElement('p');
55+
56+
// 2. Add content
57+
newPara.innerText = "I was created by JavaScript!";
58+
59+
// 3. Put it on the page
60+
document.body.appendChild(newPara);
61+
```
62+
63+
## Let's Practice: The Dark Mode Toggle
64+
65+
Let's build a simple feature that changes the background color when a button is clicked.
66+
67+
**HTML:**
68+
69+
```html
70+
<button id="theme-btn">Switch Theme</button>
71+
```
72+
73+
**JavaScript (`script.js`):**
74+
75+
```javascript
76+
const themeBtn = document.getElementById('theme-btn');
77+
78+
themeBtn.addEventListener('click', () => {
79+
// Check the current color
80+
if (document.body.style.backgroundColor === "black") {
81+
document.body.style.backgroundColor = "white";
82+
document.body.style.color = "black";
83+
} else {
84+
document.body.style.backgroundColor = "black";
85+
document.body.style.color = "white";
86+
}
87+
});
88+
```
89+
90+
## 5. Common DOM Properties
91+
92+
<Tabs>
93+
<TabItem value="text" label="Text & HTML" default>
94+
* `.innerText`: Changes just the text.
95+
* `.innerHTML`: Changes the text AND allows you to add HTML tags.
96+
</TabItem>
97+
<TabItem value="classes" label="Classes">
98+
It is better to change classes than individual styles:
99+
* `element.classList.add('active')`
100+
* `element.classList.remove('hidden')`
101+
* `element.classList.toggle('dark-mode')`
102+
</TabItem>
103+
</Tabs>
104+
105+
:::info Don't Over-CSS in JS
106+
Avoid writing too much `element.style.color = "red"` in your JavaScript. Instead, define a class like `.error { color: red; }` in your CSS file and use JavaScript to `.add('error')`. This keeps your logic and design separate!
107+
:::

0 commit comments

Comments
 (0)