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

Build a quiz...pt 1

When we opened the exercise the function(message) was used but not explained. Ive managed to break down the code and see how the rest of the programme was achieved but I'd like to know how to call the code without that particular function.

All i have is the below and i know its broken but how to get it working....

var questions = [

    ['how many state in the US?', 50],
    ['how many continents in the world?', 7],
    ['how many legs has an insect?', 6]

];

var correctQuestions = 0; var question; var answer; var response; var html;

for(var i = 0; i < questions.length; i++){

    question = questions[i][0];
    answer = questions[i][1];
    repsonse = parseInt( prompt(question) );

}

Hi David,

It looks like your code does run and prompts for the questions. You can test this by opening the browser's console, and pasting in your code, then hitting enter. You should then see prompts for each of your questions. Note, I'm unfamiliar with the exercise, but it doesn't look like you're currently doing anything with the response or answer in the questions array, so maybe that's something you can look at next?

Best,

Taylor

1 Answer

Steven Parker
Steven Parker
243,656 Points

There's a bit of code yet to write.

As Taylor suggested, it doesn't look like this program is finished yet. You still have some major functionality to write in that is currently missing. You ask the question and get a response, but you still need to:

  • determine if the answer is correct or not
  • keep score
  • report on the results after all questions are asked