Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There's a <em>lot</em> that doesn't make much sense with your code.</p> <p>First, what is <code>userResponse</code>? Where does this get defined and where is it set? Have you verified under a debugger that it is indeed <em>equal</em> to "girl"?</p> <p>Second, you probably meant to use a <em>comparison equals</em> not an <em>assignment equals</em> here:</p> <pre><code>if (userResponse = "girl") { // This should be == </code></pre> <p>However, this should not prevent the block from running. In fact, it will force the block to <em>always</em> run since "girl" is true-ish.</p> <p>Third, what is <code>girlnames</code>? Is it an array? Where is this defined? Have you verified it indeed contains valid items?</p> <p>Lastly, I believe your <code>for</code> loop is incorrect:</p> <pre><code>for (var i = 0; i &lt;= girlnames.length; i++) { </code></pre> <p>Should be:</p> <pre><code>for (var i = 0; i &lt; girlnames.length; i++) { </code></pre> <p>Arrays start at 0, thus <code>girlnames[girlnames.length]</code> is not a valid item.</p> <p>However, considering you don't <em>use</em> the <code>i</code> variable in your loop anywhere, again this should not <em>actually</em> cause any errors.</p> <p>I would step through your code line by line using a script debugger (usually <kbd>F12</kbd> in modern browsers) and set a break point at:</p> <pre><code>var lastname = $('#lastnameresponse').val(); </code></pre> <p>Then verified each line is behaving correctly. If that still doesn't work, you'll need to post more of your code so we can get a better idea of what's going on.</p> <p><strong>UPDATE:</strong></p> <p>Based on your comment:</p> <blockquote> <p>Here is where the userResponse variable is defined: $(document).ready(function(){ $("#girlimg").click(function() { var userResponse = prompt("Confirm the gender you selected").toLowerCase; $('html, body').animate({ scrollTop: $(".LastName").offset().top }, 2000);</p> </blockquote> <p>It seems that <code>userResponse</code> gets declared within the click handler for the <code>#girlimg</code> tag:</p> <pre><code>$("#girlimg").click(function() { // Everything declared here is local to this function var userResponse = confirm(); // local variable }); </code></pre> <p>Thus, it would not be accessible in the click handler for <code>.button3</code>. You'll need to declare <code>userResponse</code> in a scope that is accessible to both functions. Perhaps global (this is frowned upon in JavaScript) or within your <code>$(document).ready()</code> code, provided both click event handlers are defined within that block.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload