Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Use the for
loop to iterate over an array of song names and display them on a web page.
Get the average of an array of scores
In the following example, a for
loop accesses each number in the scores
array and adds it to the current value of total
. When the loop completes, the console displays the average score by dividing the value of total
by the length of the scores
array.
const scores = [ 20, 50, 75, 100, 115 ];
let total = 0;
for ( let i = 0; i < scores.length; i++ ) {
total += scores[i];
}
console.log( total / scores.length );
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Rouchen Sun
1,834 PointsUncaught ReferenceError: createListItems is not defined
Posted by Rouchen SunRouchen Sun
1,834 Points1 Answer
-
Claire Kao
4,393 Points1 Answer
-
Genesis Mukassa
1,728 Points2 Answers
-
Kristine Zakaite
2,236 Points2 Answers
-
n r
7,665 Points1 Answer
-
Peter Huang
5,427 Points2 Answers
-
Geovani Mejia
Front End Web Development Techdegree Student 7,940 Points2 Answers
-
cameron williams
1,819 Points1 Answer
-
Keith Grimes
10,362 Points1 Answer
-
karan Badhwar
Web Development Techdegree Graduate 18,135 Points1 Answer
-
AHARON YOSEF
2,413 Points1 Answer
-
Alex Godfrey
9,249 Points1 Answer
-
Esther AlQaisi
2,311 Points1 Answer
-
Hanwen Zhang
20,084 Points2 Answers
-
Hanwen Zhang
20,084 Points1 Answer
-
PLUS
Tyson Denis
Front End Web Development Techdegree Graduate 15,805 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up