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 trialLuqman Shah
3,016 PointsI'm not given the option to delete this question - PLEASE IGNORE!
I've got the screenshot here. For some reason I can't understand why line 4 is undefined, there doesn't seem to be a syntax error.
Just the first 5 lines of code:
var questions = [
['How many states are in the United States?', 50]
['How many continents are there?', 7]
['How many legs does an insect have?', 6]
];
All of the code:
var questions = [
['How many states are in the United States?', 50]
['How many continents are there?', 7]
['How many legs does an insect have?', 6]
];
var correct = [];
var wrong = [];
var correctAnswers = 0;
var wrongAnswers = 0;
var question;
var answer;
var response;
var html;
var correctString;
var wrongString;
function print(message) {
document.write(message);
}
for (var i=0; i < questions.length; i +=1) {
question = questions[i][0];
answer = questions[i][1];
response = parseInt(prompt(question));
if (response === answer) {
correctAnswers += 1;
correct.push(questions[i][0]);
} else {
wrongAnswers +=1
wrong.push(questions[i][0]);
}
}
html = "You got " + correctAnswers + " question(s) right.";
html = "You got " + wrongAnswers + " question(s) wrong.";
print(html);
html = "<h3>You got these questions correct:</h3>"
html += correctAnswers.join(',');
html = "<h3>You got these questions incorrect</h3>";
html += wrongAnswers.join(',');
1 Answer
Steven Parker
231,269 PointsThis looks familiar, did you ask it before?
But the issue is that the inner arrays need to be sparated by commas:
var questions = [
['How many states are in the United States?', 50], // <-- comma added
['How many continents are there?', 7], // <-- comma added
['How many legs does an insect have?', 6]
];
Luqman Shah
3,016 PointsLuqman Shah
3,016 PointsYeah that worked, I did ask it a few minutes ago but this question is a general question plus the problem I was facing for the code challenge video. But now I can't delete this thread it just gives me the option to edit. Thank you though.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsAs you noticed, the option to delete a question is no longer available once it has been answered.
Happy coding!