Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Trying to update a class

https://w.trhou.se/1944i8h8sm

Hi there, I'm trying to understand updating a class, I'd like to get both items of "onOffer" Class and add a string of "(50% Off)" so will display Apples (50% Off) and Strawberries (50% Off).

I find I usually stick to Ids all the while as I dont understand accessing classes and updating them. So I tried here and am stuck, I created this project Just to learn classes, would be great if someone could help me then I can move forward.

Happy coding, Jason :-)

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Rohald van Merode
Treehouse Staff

Hi jas0n 👋

I just had a look at your code and I think you're very close to the result you're after 🔥 If you log element to the console you'll see that you're adding the 2 strings together perfectly. The thing is though that you're currently storing it in the element variable and you're not doing anything with that combined string after that.

What you'll want to do to make it display to the screen is set the cheaper[0].textContent to be that combined string for example like so:

let element = cheaper[0].textContent + discount;
cheaper[0].textContent = element