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

How do I get "your answer" to show up when a user answers a question. Your answer: Correct answer:

I can get the "correct answer to show up but not sure how to get the "your answer" response. I am trying to compare the user answer to the correct answer. This is what I have. I think I just need to know how to define response.

for (let i = 0; i < questions.length; i += 1) { question = questions[i][0]; answer = questions[i][1];

console.log(input.question(question)); if (response === answer) { console.log(Your Answer: ${response}, \n Correct Answer: ${answer}); } else { console.log(Your Answer: ${response}, \n Correct Answer: ${answer}); } }

1 Answer

Hi Sarah Early,

Great job so far. I’ll touch on just a few things.

One. It looks like maybe you have some experience with a different language, because you’re using the word input, but it looks to me that you’re intending to use the prompt keyword.

Where you’ve written console.log(input.question(question)), I don’t believe you need to log anything to the console at that point (depending on what you’re going for). What I would suggest would be for you to display the question (defined in the question variable) to the user usingprompt(question)`. The prompt method is a built-in method that returns a string, and so you can store the returned string in a variable response that you would declare.

Two. In order for your string interpolation to work properly you’ll need to wrap the string in back tics “`”.

Three. The way your code is currently written, you do not need an if...else statement, because the same code is run regardless of whether response === answer or not.

Hope this helps. If not, let me know.

Thanks Brandon. I was able to figure it out but I appreciate the input. Now I am trying to show results. I have 5 questions and I need to be able to calculate the % correct. I think I just need to step away but I am having a difficult time trying to get that calculated.