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

shaun bolak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
shaun bolak
Front End Web Development Techdegree Graduate 18,080 Points

Don't give up!

I spent about ten hours being stuck on the code below. Often times I get through the challenges without a hitch. However, this is not the first time that I have hit a proverbial "wall".

My advice is, go back to square one. Re-watch any videos that are on the subject of the code that is giving you an issue. Looking at the problem the next day does often help. Scour any articles that you can, and worse case, pick up a book and read more about it. Odds are that you are just not seeing the answer yet, or you just have not fully grasped the concepts to apply them.

Take a look at my code, if it helps: https://w.trhou.se/eb28v38oan

But exhaust all other options before you do. And, don't give up! If you keep researching and viewing similar code, you will figure it out. Good luck!

At some point this HAS to get easier : )

2 Answers

1) You could write the function without a parameter. Or replace each instance of the word quiz with the word questions inside your function. Either will work. You could also not put the code in a function since you can't call it twice without resetting all the arrays initially inside the function anyways.

2) correctAnswers.length gives you a count of the number of items in correctAnswers which is equivalent to the value of correctAnswerCount. By using this you can eliminate

var correctAnswerCount = 0;

and

correctAnswerCount++;

and just have

print("You answered " + correctAnswers.length + " answers correctly" + "<br>");
shaun bolak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
shaun bolak
Front End Web Development Techdegree Graduate 18,080 Points

Hi Kris^^

I apologize for the (very) late response. Thank you fore your comments. I should have responded earlier. But, regardless, I ended up having a better understanding of how functions work because of you. Thanks again for being awesome.

Good job. Some comments:

  • You have questions as a parameter for promptQ but you don't use it in the function
  • correctAnswerCount could be eliminated by using correctAnswers.length instead
shaun bolak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
shaun bolak
Front End Web Development Techdegree Graduate 18,080 Points

Hi Kris,

Thank you for your comments. In this instance, should I simply write the function without any parameter (i.e. "function promptQ()" )?

Also, could you show me an example of what you mean by "correctAnswerCount could be eliminated [...] by using .string"? For my own edification and clarity, it would sincerely help.

Thank you^^