Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Arrays!
You have completed JavaScript Arrays!
Preview
This video covers one way to improve the quiz program by keeping track of the number of questions answered correctly and incorrectly.
Function for creating list items:
function createListItems(arr) {
let items = '';
for (let i = 0; i < arr.length; i++) {
items += `<li>${arr[i]}</li>`;
}
return items;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
If you didn't get everything,
0:00
you can code along with me
while I show you how I did it.
0:01
I'll start with keeping track of questions
that were answered either correctly or
0:03
incorrectly.
0:08
Up top,
I'll create two empty arrays to hold each
0:09
set of questions, correct and incorrect.
0:13
When a user types the correct
answer to a question,
0:20
I'll add that question
to the correct array.
0:24
The if statement here checks if the user's
response matches the correct answer.
0:27
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