public/subjects/pimp-my-style/README.md

60 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2020-06-15 21:33:28 +00:00
## Pimp my style
### Instructions
Check out that button on the HTML page:
```html
<button class="button">pimp my style</div>
2020-06-15 21:33:28 +00:00
```
2022-06-15 21:28:30 +00:00
For now, it's only a lonely, basic and sad element. let's pimp it up.
2020-06-15 21:33:28 +00:00
On each click on the page, a function `pimp` is triggered.
Write the body of that function so that the button's class is altered:
2022-06-15 21:28:30 +00:00
- From the data file provided, add each of the `styles` array elements as classes, in order.
2022-06-28 10:33:26 +00:00
- When the end of the array is reached, remove the classes in a LIFO fashion.
2022-06-15 21:28:30 +00:00
- While removing classes, toggle the `unpimp` class on. And toggle it off again while adding classes.
2020-06-15 21:33:28 +00:00
Example for a `styles` array with only 3 classes:
2022-06-15 21:28:30 +00:00
```js
["one", "two", "three"]
```
2020-06-15 21:33:28 +00:00
2022-06-15 21:28:30 +00:00
```
Page load --> <button class="button"></button>
2020-06-15 21:33:28 +00:00
...adding
Click 1 --> <button class="button one"></button>
Click 2 --> <button class="button one two"></button>
2020-06-15 21:33:28 +00:00
...toggling `unpimp`
Click 3 --> <button class="button one two three unpimp"></button>
2020-06-15 21:33:28 +00:00
...and removing backwards
Click 4 --> <button class="button one two unpimp"></button>
Click 5 --> <button class="button one unpimp"></button>
Click 6 --> <button class="button"></button>
2020-06-15 21:33:28 +00:00
```
2021-03-04 19:25:32 +00:00
### Files
2020-06-15 21:33:28 +00:00
2024-01-21 03:18:01 +00:00
You only need to create & submit the JS file `pimp-my-style.js`. We're providing you the following files to download and test locally.:
2021-09-06 09:14:23 +00:00
- the HTML file [pimp-my-style.html](./pimp-my-style.html) to open in the browser, which includes:
2022-06-15 21:28:30 +00:00
- the JS script running some code, and which will enable you to run yours.
- the data file [pimp-my-style.data.js](./pimp-my-style.data.js) from which you can import `styles`.
2020-06-15 21:33:28 +00:00
- feel free to use the CSS file [pimp-my-style.data.css](./pimp-my-style.data.css) as it is or you can also modify it.
2020-06-15 21:33:28 +00:00
### Expected result
You can see an example of the expected result [here](https://youtu.be/VIRf3TBDTN4)
2022-06-15 21:28:30 +00:00
### Notions
- [classList](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList): `add()`, `remove()`, `toggle()`