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
renedoukhan
4,761 PointsI cant find where's my mistake in that basic js program
var bonneReponse; var retourBonne; var retourFaux;
var quizz= [
['Nom des trois Patriarches?', 'Abraham, Yitshak, Yaakov'],
['Ma date de naissance?', '29-03'],
['Mon smartphone?', 'lg g3']
];
for (i=0; i<= quizz.length; i++) { var reponse = prompt (quizz[i][0]); if (reponse === (quizz[i][1])){ bonneReponse+= 1; retourBonne = retourBonne + ' ' + (quizz[i][1])
} else {
retourFaux = retourFaux + ' ' + (quizz[i][1])
}
}
document.write ('<p>' + 'Vous avez un score de ' + bonneReponse + 'bonnes réponses sur 3' +'</p>');
document.write ('<h1>Bonnes réponses : ' + retourBonne +'</h1>'); document.write ('<h1>Mauvaises réponses: ' + retourFaux + '</h1>')
1 Answer
Leslie Heinzen
26,662 PointsHi Rene,
Your logic looks fine, but when you define your variables at the top, try establishing types to avoid running into NaN and undefined errors later on. For example:
var bonneReponse = 0;
var retourBonne = '';
var retourFaux = '';
One more thing: the condition in your for loop should be i < quizz.length, not i <= quizz.length. Otherwise you will get an error.
Hope that helps.
Happy coding,
Leslie
Sam Baines
4,315 PointsSam Baines
4,315 PointsIt looks like you might be missing some semi-colons (;) in your code - so first just double check all your syntax for simple errors.