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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

My go at the first Array challenge in JS Loops and Objects

I have followed a few good programming conventions such as declaring variables at the top of the screen, created the two dimensional array correctly and the for loop. I know how to iterate through an array, and a multidimensional array.

I followed the video solution in the end but this was my attempt

var numCorrectAnswers = 0;
var listCorrect
var listIncorrect;

//questions
var askOne;
var askTwo;
var askThree;


var quiz = [
  ["Who Wrote Harry Potter", "J.K. Rowling"],
  ["How many countries make up the United Kingdom?", "Four"],
  ["Who Wrote James Bond?", "Ian Fleming"]

];


for(var i=0; i<quiz.length; i+=)
{
  quiz[i][1]
}


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

So I'm probably about half way there. This was me following everything I knew from the top of my head to do the challenge. When comparing it to the solution I can see that I declared my variables preparing them for the wrong reasons. I didn't even use the variables I made for the individual questions so I just lost heart and went to the video solution.

But I didn't really get how to use the variables to compare the input to the answers. It seems so simple when looking at the solution but I just didn't get it.

I also noticed in the solution that the quiz was only for number answers and my answers are strings, even the "number" answer.

What do you think about where I go from here? Try again or just study the solution more? Thanks. :)

1 Answer

Hey Jonathan,

I would definitely say keep on trying, man. When you finally figure out something for yourself, it is incredibly satisfying. But if you have any specific questions, there are a bunch of us who are willing to help!