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 JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 2 Solution

My program doesn't print to the browser window, could someone help?

I tried solving the challenge on my own, but it didn't print the result to the browser window. I watched this video, and rewrote my program accordingly, but no matter what I do, the result won't be printed to the browser window. I've linked a snapshot of my workspace below. Any help would be appreciated.

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

1 Answer

Hi there Oneeb!

Bug was in function buildList. In for loop after comparing operation

j <= arr.length()

you were trying to invoke length() method from array object. But it is a property. Removing parentheses solved the problem.

Another small problem appears after whole list of right and worng answers were displayed. Undefined string, each time in right or wrong section. To remove this small problem you need to first

change comparing operator from <= to < in for loop(buildList function).

j < arr.length

And after that add check if array that comes to the function is not empty. This will also helps you to avoid new visual bugs ;)

Below you can find improved buildList method.

function buildList(arr) {
    if (arr.length) {
        var listHTML = "<ol>";
        for (var j = 0; j < arr.length; j += 1) {
            listHTML += "<li>" + arr[j] + "</li>";
        }
        listHTML += "</ol>";
        return listHTML;
    } else return "Nothing to show";
}

Best regards!

Thank you very much! That was extremely helpful!

you are welcome ;)