Skip to content

Commit f463e2d

Browse files
committed
Update build-a-randomizer-generator-with-html-css-js.mdx
1 parent df570d9 commit f463e2d

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

projects/build-a-randomizer-generator-with-html-css-js/build-a-randomizer-generator-with-html-css-js.mdx

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ The HTML and body elements use flexbox to center the content both horizontally a
100100
html {
101101
background-color: #ff5f1f;
102102
display: flex;
103-
justify-content: center; /* Center horizontally */
103+
justify-content: center;
104104
font-family: sans-serif;
105105
margin: 0;
106106
padding: 0;
107107
height: 100%;
108-
overflow-x: hidden; /* Prevent horizontal scrolling */
108+
overflow-x: hidden;
109109
}
110110
```
111111

@@ -116,10 +116,10 @@ The `.main-container` holds all of the sections (like the images and buttons). T
116116
```css
117117
.main-container {
118118
display: flex;
119-
flex-direction: column; /* Stack elements vertically */
120-
align-items: center; /* Center content */
121-
gap: 15px; /* Add space between items */
122-
padding: 10px; /* Small padding around the container */
119+
flex-direction: column;
120+
align-items: center;
121+
gap: 15px;
122+
padding: 10px;
123123
}
124124
```
125125

@@ -131,10 +131,10 @@ The images in the outfit categories (add-ons, tops, bottoms) are set to take up
131131
.addons-image,
132132
.tops-image,
133133
.bottoms-image {
134-
width: 90%; /* Take up 90% of the container's width */
135-
max-width: 250px; /* Don't exceed 250px in width */
136-
aspect-ratio: 3 / 4; /* Maintain consistent proportions */
137-
object-fit: contain; /* Preserve image aspect ratio */
134+
width: 90%;
135+
max-width: 250px;
136+
aspect-ratio: 3 / 4;
137+
object-fit: contain;
138138
}
139139
```
140140

@@ -146,19 +146,23 @@ The buttons are styled with a bright pink background and white text. A hover eff
146146
button {
147147
font-size: 1rem;
148148
color: white;
149-
background-color: #ff69b4; /* Pink background */
149+
background-color: #ff69b4;
150150
padding: 8px 16px;
151151
cursor: pointer;
152152
}
153153

154154
button:hover {
155-
background-color: #d90166; /* Darker pink when hovered */
155+
background-color: #d90166;
156156
}
157157

158158
.random-button {
159-
background-color: green; /* Green button for "randomize" */
159+
background-color: green;
160160
}
161161
```
162+
163+
Here's what out generator will look like at this point:
164+
<RoundedImage link="https://i.imgur.com/v6R1K0o.png" description="" />
165+
162166
## JavaScript
163167

164168
### Randomizer Logic
@@ -224,48 +228,51 @@ document.getElementById(category.prevBtn).addEventListener("click", () => {
224228
225229
The `%` modulo operator is used here to make the images cycle in a continuous loop.
226230
227-
## Avatar Creator
231+
Voila! Here's our final result for the outfit generator.
232+
<RoundedImage link="https://i.imgur.com/1lTRM6l.png" description="" />
233+
And here's our [final code](https://www.codedex.io/@Julien/build/randomizer-generator-final-code).
234+
235+
## Bonus Challenges
236+
237+
### Avatar Creator
228238
229239
You can use the same logic above to create a monster or an avatar. Here's a fun example, using the heads, torsos, and legs of monsters from Monster's Inc, Inside Out, Minions.
230240
231241
<RoundedImage link="https://i.imgur.com/HHmRCzg.png" description="" />
232242
233243
This example also shows an alternate way of designing the arrows so the three characters swap heads, torsos, and legs at the same time.
234244
235-
## Adding more categories
245+
### Adding more categories
236246
237247
So – what if we have our avatar and want to add another category, like shoes? Here's how we'd do that:
238248
239-
### HTML
240-
241249
In the HTML, you'll need to add a new section for shoes. This will look similar to how the other sections are structured. You would add the following HTML code:
242250
243251
```html
244252
<div class="shoes-container">
245253
<img id="shoes" class="shoes-image" src="" alt="shoes" />
246254
<div class="carousel-buttons">
247-
<button id="3prevBtn"><--</button>
248-
<button id="3nextBtn">--></button>
255+
<button id="3prevBtn">⬅️</button>
256+
<button id="3nextBtn">➡️</button>
249257
</div>
250258
</div>
251259
```
252260
253261
This creates a new section with an image for shoes and navigation buttons (previous and next). You can place this code in the `<div class="main-container">` along with the other categories.
254262
255-
### CSS
256-
To add styling for the shoes category, follow the same pattern as for other categories! Anywhere that you currently have
263+
To add CSS styling for the shoes category, follow the same pattern as for other categories! Anywhere that you currently have
257264
```css
258265
.addons-image,
259266
.tops-image,
260-
.bottoms-image {
267+
.bottoms-image
261268
```
262269
You'll also add `.shoes-image`.
263-
### JavaScript
270+
264271
In JavaScript, you'll need to add a new category to the categories object. Each category includes an array of images, an index to track the current image, references to the HTML elements, and button IDs for navigation. Here's how you'll add the shoes category:
265272
```
266273
const categories = {
267274
268-
shoes: { // Add new category for shoes
275+
shoes: {
269276
images: [
270277
// Your shoe images go here
271278
],
@@ -278,18 +285,17 @@ const categories = {
278285
```
279286
You'll add a `shoes` key with an array of image URLs, an index to track the current image, an element to target the HTML image element, and button IDs for the next and previous buttons.
280287
281-
## Bonus Challenge
288+
### Mismatch
282289
283290
If you've already added a fourth section, try making a feature that toggles a pop-up that says "mismatch!" when the outfit doesn't match. Or, if you're creating a monster, the feature could say the sound the monster would make, depending on the combinations.
284291
285292
<RoundedImage link="https://i.imgur.com/4VYyB9N.jpeg" description="" />
286293
287-
288294
## Conclusion
289295
290296
Congrats! You've built your own generator! Now you're equipped with the skills to build on this concept and create other kinds of generative projects!
291297
292-
Here's our [final code](https://www.codedex.io/@Julien/build/randomizer-generator-final-code).
298+
P.S. Are you waiting for an Avatar Builder on Codédex? Keep an eye out!
293299
294300
## Additional Resources
295301

0 commit comments

Comments
 (0)