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
Elias Guderian
Front End Web Development Techdegree Graduate 14,994 PointsHere is my puzzled together solution
I tried many different approaches and came up with a sort of a Fankenstein of a solution. It has some elements in it that we had not yet touched on, like arrays and for loops and I have to add I was only able to complete the challenge once I saw the solution video but I wanted to share it anyway. https://w.trhou.se/b112tu2egg
2 Answers
Piotr Manczak
Front End Web Development Techdegree Graduate 29,609 PointsPure and clear. I like it. Why did you include numbers into the array?
Connor Walker
17,985 PointsThat's looking pretty good, especially as that's been done before the course went over those topics.
If you're willing to read ahead further, the way that you have laid out your code presents the perfect opportunity to look into JavaScript Objects, with your quiz array becoming an array of objects rather than an array of arrays. This would help make your code even more readable.
So for example this:
var quiz = [
[1, 'Which language is not a programming language?', 'html'],
]
Could become this:
var quiz = [
{ number: 1, question: 'Which language is not a programming language?', answer: 'html' }
]
Whilst this look like more writing it would make your for loops and if blocks read more like english:
for ( var i = 0; i < quiz.length; i++ ) {
answer = prompt(quiz[i].question);
if ( answer.toLowerCase() === quiz[i].answer) {
correct += 1;
}
}
It's a small change but it can help a lot in some cases. If you are interested in looking into this then W3Schools and The MDN have good resources on them
Elias Guderian
Front End Web Development Techdegree Graduate 14,994 PointsThat is very interesting and it definitely helps with understanding the code better. Thank you for the suggestion.
Elias Guderian
Front End Web Development Techdegree Graduate 14,994 PointsElias Guderian
Front End Web Development Techdegree Graduate 14,994 PointsI got this from a Youtube video while searching for a good solution and as far as I understand it, it is for visual aid.