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 1

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

m stuck after creating the two dimensinal array! tried creating a loop and condition statments

but its not giving desired results , any brief sketch of the solution that i shud b doin to make this programme a success:/

Gaurav Yadav
Gaurav Yadav
5,047 Points

Please provide code that you were working on, so that we can help you!

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

not proud of it thats why dint share it earlier:/ i know i have to make lists but dont know where to start:/ plus somehow m still trying to figure out how to get correct answers together and add them to show total answered correctly........... and wrong seperately

var quiz = [
['What is England capital Name?', 'london' ],
['What is currency used in UK?', 'pound'],
['Where does the Jorden river end up?', 'deadsea']
];
var question;
var answer;
var correctAnswer= 0;

function print(message) {
  document.write(message);
}
function printResult(){
  for (var i = 0; i< quiz.length; i+=1){

var question = prompt (quiz[i][0]);
var answer = quiz[i][1];
if (question === answer){
  checkAnswer= answer.toLowerCase;
  correctAnswer +=1;
  print('you got '+ correctAnswer +' right.You have answered these questions correctly');
  print(quiz[i][0]);

}   else {
print ('You got '+ correctAnswer + ' wrong. have got these questions wrong ');
  print(quiz[i][0]);

}  
}
}
printResult();

1 Answer

Gaurav Yadav
Gaurav Yadav
5,047 Points

Okay, so you are doing great...just some mistakes

  1. You are mixing two challenges, in the first challenge you just have to display how many questions user answered correctly, you do not have to display which answers were correct and which were wrong. Do first part of challenge first, then in the next video, the teacher will give you the next task.
  2. i saw a mistake in your code, the operator you used to increase correctAnswer variable is wrong ie. correctAnswer=+1;, u should use "+=" instead of "=+"
Saqib Ishfaq
Saqib Ishfaq
13,912 Points

really? lol thats wot not great shud look like, yeh i rectified the mistake u mentioned n corrected it already but still same issue! okkk let me see if i can jst do jst the part u saying

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

just saw the next video, n i was annoyed why m not getting it right! it is wot u said a breakup of 2 challenges, cud hv been simpler if teacher had mentioned it in the 1st challenge video (thumbs up)