Company Homepage with FlexBox Project - Why is my javascript not working?


I was pretty confident in my FlexBox knowledge, so I added a bit of javascript with this project cause I really wanted to practice that sometime.

In my javascript I do a bit of DOM manipulation but nothing complex at all. Unfortunately, it’s not working. Can anybody tell me why my javascript is not adjusting the elements that I want it to adjust?

I believe I covered everything else that this project requested.

Here is the code: GitHub - RenSylvain/LevelUp: Codecademy Project to practice flexbox skills. I included some javascript work as well.

Here is the live website: Hero Tracker

Thanks for any help/feedback.

Hi so I’ve found a couple of things! Firstly it seems like there’s a missing closing bracket ) for the start of the if statement, which is causing the JS to not run correctly. When I added this I got an average showing up however the average was incorrect.
Upon investigation I found that you’re not converting the numbers in the loop. Recall that you are fetching the text content of the elements. This is by default, a string, and is not automatically converted for you. Therefore when you are doing total + heroLvls[i].textContent, it is actually concatenating strings instead of creating a sum integer. You need to converse these to integers before summing. If you do this hopefully you will arrive at the solution to your issue.

1 Like

Well done with and thank you very much for the help!

It’s interesting because before I took a break and went for a walk, I couldn’t even get the average to show at all on the webpage. I think I must not have had one file saved or something. Even when I hard-coded a value for ‘avgAnswer’, it wouldn’t show.

Anyway, once I corrected both errors that you pointed out everything worked great. Feels good to finally code some javascript into a site and know that I can do it. Thank you!

1 Like