Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there something like an if mismatch or an else loop. I need help making this JavaScript Script work
    primarykey
    data
    text
    <p>How would i get a response according to a mismatch, or possibly like an Else loop but this doesn't appear to work since i get it even if i answer the question correctly, and if maybe i could do something like and if mismatch or something. I am new to JavaScript, so i cannot solve this myself.</p> <pre><code>var PromptAnswer3 = prompt("Well, what sports do you like to play?", ""); while (PromptAnswer3 === null | PromptAnswer3 === "") { alert("You didn't answer"); PromptAnswer3 = prompt("Well, what sports do you like to play?", ""); } if (PromptAnswer3.match(/^(tennis|bowling|baseball|soccer|basketball|football|cricket|hockey|ice|hockey|rugby|track|golf|horseracing|water polo|swimming|biking|gymnastics|cheer-leading|skiing|snowboarding|iceskating|lacrosse|surfing|archery|boxing|kayaking|diving|spelunking|fencing|karate|judo|rockclimbing|softball|volleyball|wrestling|badminton|javelin throwing|synchronized swimming|yoga|ringette)!?$/i)) { alert("Haha yeah, " + PromptAnswer3 "is pretty awesome."); } while (PromptAnswer3) { alert("I don't think that is a sport."); PromptAnswer3 = prompt("Well, what sports do you like to play?", ""); } </code></pre> <p><strong>Edit [should possibly be added as an answer]</strong></p> <p>This is what i did to make it work. It is simple and easy. I followed some of the peoples advice on the answers and put the if statement in the loop, while (PromptAnswer3), and put an else and a break in the if so that it wouldn't loop after the first time.</p> <pre><code>else { var PromptAnswer3 = prompt("Well, what sports do you like to play?", ""); while (PromptAnswer3 === null | PromptAnswer3 === "") { alert("You didn't answer"); PromptAnswer3 = prompt("Well, what sports do you like to play?", ""); } while (PromptAnswer3) { if (PromptAnswer3.match(/^(tennis|bowling|baseball|soccer|basketball|football|cricket|hockey|ice|hockey|rugby|track|golf|horseracing|water polo|swimming|biking|gymnastics|cheer-leading|skiing|snowboarding|iceskating|lacrosse|surfing|archery|boxing|kayaking|diving|spelunking|fencing|karate|judo|rockclimbing|softball|volleyball|wrestling|badminton|javelin throwing|synchronized swimming|yoga|ringette)!?$/i)) { alert("Haha yeah, " + PromptAnswer3 + "is pretty awesome."); break; } else { alert("I don't think that is a sport."); PromptAnswer3 = prompt("Well, what sports do you like to play?", ""); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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