# Assessment wanted for Events 3 skill test//

**URL:** <https://discourse.mozilla.org/t/assessment-wanted-for-events-3-skill-test/92096>\
**Category:** Learn\
**Created:** [January 27, 2022, 3:49pm UTC](https://discourse.mozilla.org/t/assessment-wanted-for-events-3-skill-test/92096 "2022-01-27T15:49:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brusli](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@brusli](https://discourse.mozilla.org/u/brusli)\
**Post date:** [January 27, 2022, 3:49pm UTC](https://discourse.mozilla.org/t/assessment-wanted-for-events-3-skill-test/92096/1 "2022-01-27T15:49:50Z")

</div>

Can I pls get my work assesed. TY  
https://codepen.io/leon147/embed/preview/XWzJvZy?default-tabs=html%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=XWzJvZy

> **[Test your skills: Events - Learn web development | MDN](https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/Test_your_skills:_Events)**
>
> The aim of this skill test is to assess whether you've understood our Introduction to events article.

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [January 29, 2022, 11:43am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-events-3-skill-test/92096/2 "2022-01-29T11:43:36Z")

</div>

Hi @brusli

The task asks you to set the background of the `button-bar`. Therefore we need to work with `buttonBar.style.backgroundColor` instead of `e.target.style.backgroundColor`. This should make the exercise run correctly.

There are more things you can consider to simplify the code:

- You don’t need to add the classes as we have the color information inside the `data-color` attribute. These can be accessed in JS with the [`getAttribute()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute) method.
- In the nested `if..else` statements you are testing for the color and then adding the color. You can get rid of those statements and directly assign the attribute value to the background. Do you know what I mean?

I hope those hints help you improve your code. Please ask if you need more help. I didn’t want to just post the solution and spoil the fun 😁

Have a nice weekend,  
Michael

---

<div class="post-metadata">

**Author:** ![brusli](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@brusli](https://discourse.mozilla.org/u/brusli)\
**Post date:** [January 30, 2022, 1:46pm UTC](https://discourse.mozilla.org/t/assessment-wanted-for-events-3-skill-test/92096/3 "2022-01-30T13:46:49Z")

</div>

Hi @mikoMK  
Thank you for your feedback.  
I think the exercise is now running correctly.  
https://codepen.io/leon147/embed/preview/XWzJvZy?default-tabs=js%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=XWzJvZy

```javascript
You don’t need to add the classes as we have the color information inside the `data-color` attribute. These can be accessed in JS with the [`getAttribute()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute) method.

```

I dont know how to access the value of each individual `data-color` attribute without first assigning a class or an id to it. If I only use `element.getAttribute('attributeName')` I always get red.

```javascript
In the nested if..else statements you are testing for the color and then adding the color. You can get rid of those statements and directly assign the attribute value to the background. Do you know what I mean?

```

I dont know how to do it also.

Thank you very much for your help and support.  
Cheers.

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [January 30, 2022, 8:17pm UTC](https://discourse.mozilla.org/t/assessment-wanted-for-events-3-skill-test/92096/4 "2022-01-30T20:17:50Z")

</div>

You’re welcome 🙂  
Yes, now it works correctly.

You can just use this single line inside your event listener:

```auto
buttonBar.style.backgroundColor = e.target.getAttribute('data-color');

```

We get the `data-color` property from the target and then, as it’s already the color name, we can directly assign it to `backgroundColor`.  
This way we don’t need classes or `if...else` statements.
