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

This javascript program from the video tited "Improve the Quiz-One Solution" won't run.

I typed the below code from from the video "Improve the Quiz-One Solution" but I can't get it to run and I don't see any mistakes. Where are the errors?

const questions = [
  ['What liquid does all life need to survive?', 'water'],
  ['What is the largest organ of the human body', 'skin'],
  ['Is the earth round or flat','round'],
  ['Is the center of the earth hot or cold?', 'hot']
];

const correct = [];
const incorrect = [];
let correctAnswers = 0;

for( let i = 0; i < questions.length; i++ ) {
  let question = questions[i][0];
  let answer = questions[i][1];
  let response = prompt(question);
}

if( response === answer ) {
  correctAnswer++;
  correct.push(questions);
} else {
  incorrect.push(questions);
  }
}

function createListItems(arr) {
  let items = '';
  for (let i = 0; i < arr.length; i++) {
   items += `<li>${arr[i]}</li>`;
  }

let html = `
   <h1>You got ${correctAnswer} question(s) correct</h1>
   <h2>You got these questions right:</h2>
   <ol>${ createListItems(correct) }</ol>

   <h2>You got these questions wrong:</h2>
   <ol>${ createListItems(incorrect) }</ol>
`;

document.querySelector('main').innterHTML = html;

2 Answers

I finally got the code to run. Thank you for your help. It would be helpful for Treehouse to provide a downloadable file of code for the answer to each code challenge. That would have prevented me (and you) from having to search through my typos to make the code useable. Do I make that suggestion on the support page?

Steven Parker
Steven Parker
231,261 Points

The support page has instructions for submitting suggestions, but the final code is already available in the Project Files on the page's Downloads tab.

Steven Parker
Steven Parker
231,261 Points

luisgomez7 — Most folks select "Best Answer" on the one that provided the information that was helpful.   :see_no_evil:

Steven Parker
Steven Parker
231,261 Points

A few issues that I noticed:

  • correctAnswers (plural) is defined on line 10, but elsewhere there are references to correctAnswer (singular)
  • there's a stray extra closing brace on line 16
  • on lines 20 and 22 the entire list is pushed instead of just the current question
  • the function createListItems on line 26 is missing a closing brace
  • that function also does not return any value (did you mean to "return items"?)
  • line 41 has "innter" (with a "t") instead of "inner"

I corrected all the errors you noticed except the third one involving pushing info into the two arrays because I double checked it against the code in the video and it's identical. However, the program still doesn't run. This can only mean the program doesn't run as presented in the video so I would like a Treehouse emp to provide me with the correct coding. How do I do that?

Steven Parker
Steven Parker
231,261 Points

You didn't provide a link to the video, but assuming you meant this one, you can see at about 1:12 that the instructor pushes the current question ("question" singular) instead of the entire list ("questions" plural) as the code above is doing.

Unless you're one of the first to take a brand-new course, you can count on the course examples having been thoroughly tested by previous students. But if you do encounter a technical issue in any course, remember that the forum is primarily used by other students and that a more certain and rapid way to contact the staff is described on the Support page.

I also found one additional code issue and added it to my previous list.