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

How to add all class percentage totals together to get mean average?

https://w.trhou.se/2k0sy69xol

Been told by treehouse teacher to experiment to gain experience. So I'm creating my own programs to help myself learn so one day I will understand the DOM.

5 Answers

Hi jas0n!

I hope all is well for you and yours!

The mean is the average of the numbers. It is easy to calculate: add up all the numbers, then divide by how many numbers there are. In other words, it is the sum divided by the count.

From:

https://www.mathsisfun.com/mean.html

And here is a JS example using array.reduce to total the scores (percentages):

var percentages = [84, 77, 93, 68, 79, 85];
const total = percentages.reduce((total, val) => {
  return total + val;
}, 0);
const mean = total/percentages.length; // sum/count
console.log(mean);

Logged to console: 81

84 + 77 + 93 + 68 + 79 + 85 = 486

486/6 = 81

Does that answer your question?

BTW, I got my first Covid shot yesterday!?!

I hope that helps.

Stay safe and happy coding!

Hmm I got to think how to incorporate that into html, thanks though, am I ok doing function this way:-

var percentages = [84, 77, 93, 68, 79, 85];
function mypercentages(total, val) {
var sum = percentages.reduce;
return total + val;
};
var meanAve = total/percentages.length; // sum/count
console.log(mean);

I did the function this way because I find it easier to understand, still same result. Hope you and family are well.

Can I just ask you, if like me you were repeatedly failing to understand JavaScript would you think it would be better to be a web designer instead of struggling always with JavaScript? I mean its possible to get a web designer job isn't it?

These might help you understanding reduce better:

https://www.youtube.com/watch?v=R8rmfD9Y5-c (reduce starts at 6:27)

https://www.youtube.com/watch?v=rRgD1yVwIvE (reduce starts at 25:42)

(I do recommend watching the whole videos, though, to learn higher-level ES6 array functions well/better!?!)

https://www.youtube.com/watch?v=g1C40tDP0Bk

I hope that helps.

Stay safe and happy coding!

We are well!!!

U2 (you and yours)!!!

:)

Thanks for your help, I've switched tracks to do web design, I'd hopefully learn javaScript once working with web design in the future. Take care. Jas0n.

To answer your Web designer vs Web developer question, I'll just throw out a few thoughts:

I think it depends on your temperament. Do you enjoy graphics over coding/algorithms?

More info:

https://elementor.com/blog/web-designer-vs-web-developer/

I first got into programming because I took an electronic music class and was able to use a computer to sequence music, which I really enjoyed. I thought I enjoyed it because I liked music, but I later realized I like the power programming allows you to make something behave the way YOU WANT IT TOO!?!

I realized I've always had an admiration for systems and program flow.

For example, I have always liked setting up dominoes in a big pattern where you knock the first one down and they all fall down in succession. In effect, it's a (very simple) program - you start it, and if you set it up right - it runs all the way to the end.

https://www.youtube.com/watch?v=JE9yGOaF-ao

Or the mousetrap game:

https://www.youtube.com/watch?v=HgX168Gsmcg

Also:

https://www.youtube.com/watch?v=GvnEBX9aedY

https://www.youtube.com/watch?v=yuZAg9AoKrI

I've thought stuff like these were interesting my whole life!?!

(All crude versions of computer programs.)

For a long time, I fought becoming a programmer (I wanted to be a ROCK STAR - I play drums!?!), but my. father was an electrical engineer and my brother has been a Java developer for over 30 years, so it was inevitable that I gravitate towards programming - it's in my blood!?!

Also, I've always been good at math, too (going as far as scientific calculus in college) and music, math, and programming are very similar (in the way you have to process information and think logically and linearly). All three use the same kind of right/left brain balance.

Regardless, I still think you should crush HTML, CSS, and Javascript as best you can. Just know it will get easier.

I hope that helps.

Stay safe and happy coding!