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 trialSaqib Ishfaq
13,912 Pointsm 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:/
Saqib Ishfaq
13,912 Pointsnot 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
5,047 PointsOkay, so you are doing great...just some mistakes
- 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.
- 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
13,912 Pointsreally? 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
13,912 Pointsjust 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)
Gaurav Yadav
5,047 PointsGaurav Yadav
5,047 PointsPlease provide code that you were working on, so that we can help you!