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

document.getElementById('para') returns undefined.

Help: The getElementById returns 'undefined'. Followed the instructor's verbatim and still received undefined value. Please see the code below.

//first, define questions and answers in an Array var questions = [ ['what is 1 + 1?', 2], ['what is 2 + 2?', 4], ['what is 3 + 3?', 6], ]

//define variables to help make code readable var correctAnswer = 0; var question; var answer; var response; var html; var correct = []; var wrong = [];

function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML = message; }

function buildList (arr) { var myList1 = '<ol>';
for (var i = 0; i < arr.length; i += 1) { myList1 += '<li>' + arr[i] + '</li>'; } myList1 += '</ol>'; return myList1; }

//iterate through questions in variable 'questions'
for ( var i = 0; i < questions.length; i+= 1) { //set question question = questions[i][0]; //set answer to above question answer = questions[i][1]; //display question to user response = parseInt(prompt(question)); //validate answers and increment correctAnswer if (response === answer) { correctAnswer += 1; correct.push( question ); } else { wrong.push( question ); } } html += "You got " + correctAnswer + " question(s) right!"; html += '<h2>You got these questions right'; html += buildList(correct); html += '<h2>You got these questions wrong'; html += buildList(wrong); print(html);

I don't see document.getElementById('para') in your code. All I see is document.getElementById('output'). Can you post your html? Or a snapshot of your workspace?