Spunky Posted October 14, 2014 Share Posted October 14, 2014 function submitResponse(response){ if(count == 1){ switch(response){ case 'otokonoko': if(user_gender == "female" && user_age == "adult"){ //does not important stuff first_response = response; count++; include_text_prompt(); } break; case 'onnanoko': if(user_gender == "female" && user_age == "adult"){ //does not important stuff first_response = response; count++; include_text_prompt(); } break; case 'otokonohito': if(user_gender == "female" && user_age == "adult"){ //does not important stuff first_response = response; count++; include_text_prompt(); } break case 'onnanohito': if(user_gender == "female" && user_age == "adult"){ //does not important stuff } break; default: //does not important stuff first_response = response; count++; include_text_prompt(); break; } } if(count == 2){ alert(response); switch(response){ case 'otokonoko': if(user_gender == "female" && user_age == "adult"){ if(first_response == response){ //does not important stuff } else{ //does not important stuff } second_response = response; count++; include_text_prompt(); } break; case 'onnanoko': if(user_gender == "female" && user_age == "adult"){ if(first_response == response){ //does not important stuff } else{ //does not important stuff } second_response = response; count++; include_text_prompt(); } break; case 'otokonohito': if(user_gender == "female" && user_age == "adult"){ if(first_response == response){ //does not important stuff } else{ //does not important stuff } second_response = response; count++; include_text_prompt(); } break case 'onnanohito': if(user_gender == "female" && user_age == "adult"){ //does not important stuff } break; default: if(user_gender == "female" && user_age == "adult"){ //does not important stuff count++; include_text_prompt(); } break; alert("end"); } This function runs when include_text_prompt() ends, which you will also see runs at various times throughout the code. My issue is, when it gets to the if(count == 2) section (bottom half, top half is if(count == 1) and both halves are very similar), for some reason it runs the code again. The idea right now is that the answer is "onnanohito". So if response == "onnanohito" the first time while count == 1, the code ends just like it is suppose to. However, if it equals one of the other cases and thusly makes it to count == 2, if response == "onnanohito" this time, the code displays as it is suppose to, but instead of ending, it goes back to the top of where if(count == 2) is at and response now equals what it did the first time. Gosh this is hard to explain. response == "otokonoko" count = 1 submitResponse(response) runs case: "otokonoko" runs count = 2 include_text_prompt(); runs response == "onnanohito" submitResponse(response) is re-entered case: "onnanohito" runs code then makes it to the alert on bottom but then it goes back to alert(response) where you see it under if(count == 2). It doesn't even re-enter the whole function, checking count again, which it's not suppose to do anyway, and somehow when that alert runs, response == "otokonoko" again, which was what it equaled the first time through. When case: "onnanohito" runs the 2nd time through, it is suppose to end the code just like it does the first time through. Any ideas? Link to comment Share on other sites More sharing options...
Ingolme Posted October 14, 2014 Share Posted October 14, 2014 You can use else if to have exclusively one condition or the other. if(count == 1) {} else if(count == 2) {} Link to comment Share on other sites More sharing options...
Spunky Posted October 14, 2014 Author Share Posted October 14, 2014 Interesting. I felt the else if would be unnecessary, why does it cause problems without it? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 14, 2014 Share Posted October 14, 2014 You increment count through the first one, so that when you get to the second one count is set to 2 and then you go through that one also. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now