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

Roel Bakkum
Roel Bakkum
5,921 Points

Only works with document.write()

So this is my solution to the challenge. Not as slick as the eventual answer to the challenge but it does do the job. However I can get the document.getElementByid() to work.

var questions = [ ["Wat voor dag is het vandaag?", "maandag"], ["Wat voor computer is dit?", "imac"], ["Hoeveel is 12*1350?", "27000"] ];

var answer; var answerCount = [];

for (var i=0; i < questions.length; i += 1) { answer = prompt(questions[i][0]); answer = answer.toLowerCase(); if (answer === questions[i][1] ) { questions[i].push(true); answerCount.push(1); } else { questions[i].push(false); } }

function print(message) { document.write (message); }

function printResults(list){ var listHTML = "You've got " + answerCount.length + " question(s) correct"; print(listHTML); }

function printCorrect(list) { var correctHTML = "<p>You have Answered the following questions correctly:</p>" + "<ol>"; for (var i=0; i < questions.length; i+=1) { if (questions[i][2] === true) { correctHTML += "<li>" + questions[i][0] + "</li>"; } } correctHTML += "</ol>"; print(correctHTML); }

function printFalse(list) { var incorrectHTML = "You have Answered the following questions incorrectly:" + "<ol>"; for (var i=0; i < questions.length; i+=1) { if (questions[i][2] === false) { incorrectHTML += "<li>" + questions[i][0] + "</li>"; } } incorrectHTML += "</ol>"; print(incorrectHTML); }

printResults(); printCorrect(); printFalse();

Justin Otero
Justin Otero
4,959 Points

document.getElementById()

In Javascript and many other programming languages, proper lowerCamelCase is the standard nomenclature when naming methods.

document refers to the object, and after the . are the static methods/properties available on the document object.

https://www.w3schools.com/jsref/dom_obj_document.asp

1 Answer

Aryaman Dhingra
Aryaman Dhingra
3,536 Points

The JS Compiler is very picking with formatting, and everything needs to be capitalized exactly how it is in the documentation. Just change document.getElementByid(); to document.getElementById(); The change I made is in the 'id' part after 'By'. If you have any other syntax related problems, make sure to check out the JS Documentation. If this answer helped, don't hesitate to mark it as the best answer.