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 Treehouse Club - MASH MASH - JavaScript Fill in Answers and Get Answers Functions

How are the variables inputs and selector working?

I'd love a little further explanation on how the variables 'selector' and 'inputs' are working. Right now my understanding is the 'get_answer' function is called in by the 'handle_submissions function'. It passes 'category' into the 'selector' var and then the 'inputs' var searches for the string( syntax??) stored in 'selector' variable.

Furthering my comprehension, I'd also love a little run down of how they are used later in the script. Thank you for any efforts you make to help!!!

1 Answer

William Higgins
William Higgins
5,904 Points

Right now my understanding is the 'get_answer' function is called in by the 'handle_submissions function'. Correct.

It passes 'category' into the 'selector' var Correct.

and then the 'inputs' var searches for the string( syntax??) stored in 'selector' variable. Not quite. Inputs stores the result of the search. document.querySelectorAll() does the searching.

Furthering my comprehension, I'd also love a little run down of how they are used later in the script. Thank you for any efforts you make to help!!!

get_answer() returns the choices (0 to 4 values) and those values are saved in a var (profession, pet or location). fill_in_answers() will use the vars mash, profession, pet and location to initialize values for the ids in this div.

<div id="answers" class="hide"> <p>Your home is in <span id="location"></span> with a <span id="pet"></span> as you are a <span id="profession"></span> who owns a <span id="home"></span>. </div>

Why Meee
Why Meee
548 Points

I didn't really understand a lot... but it's okay :)