trying to make nr restriction 1-10, but prompt allows users to pick 13





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















so i am trying to make a tick system, where i a user can pick a number from 1-10 and there will start a countdown from the number that the user picks to 0. The problem is that when a user picks number 12 in prompt, it doesnt allow him/her to continue, but when they try again it allows them.



html:



 <button onclick=start()>Countdown</button>
<p id="p">


scirpt:



<script>
var ticks;
var mytimer;

function start() {
ticks = Number(prompt("where do you want to start a countdown, min 1 max 10")) + 1;
if (ticks > 11) {
ticks = Number(prompt("Skriv inn på nytt, tallet må være mellom 3-10")) + 1;
}
else if (ticks < 1) {
ticks = Number(prompt("Try again, The number must be between 1-10")) + 1;
}
mytimer = setInterval(tick, 1000)

}

function tick() {
ticks--;
document.getElementById("p").innerHTML = "Tick nr. " + ticks + "<br />";

if (ticks === 1) {
clearInterval(mytimer);
document.write("Done!");
}
}
</script>









share|improve this question





























    0















    so i am trying to make a tick system, where i a user can pick a number from 1-10 and there will start a countdown from the number that the user picks to 0. The problem is that when a user picks number 12 in prompt, it doesnt allow him/her to continue, but when they try again it allows them.



    html:



     <button onclick=start()>Countdown</button>
    <p id="p">


    scirpt:



    <script>
    var ticks;
    var mytimer;

    function start() {
    ticks = Number(prompt("where do you want to start a countdown, min 1 max 10")) + 1;
    if (ticks > 11) {
    ticks = Number(prompt("Skriv inn på nytt, tallet må være mellom 3-10")) + 1;
    }
    else if (ticks < 1) {
    ticks = Number(prompt("Try again, The number must be between 1-10")) + 1;
    }
    mytimer = setInterval(tick, 1000)

    }

    function tick() {
    ticks--;
    document.getElementById("p").innerHTML = "Tick nr. " + ticks + "<br />";

    if (ticks === 1) {
    clearInterval(mytimer);
    document.write("Done!");
    }
    }
    </script>









    share|improve this question

























      0












      0








      0








      so i am trying to make a tick system, where i a user can pick a number from 1-10 and there will start a countdown from the number that the user picks to 0. The problem is that when a user picks number 12 in prompt, it doesnt allow him/her to continue, but when they try again it allows them.



      html:



       <button onclick=start()>Countdown</button>
      <p id="p">


      scirpt:



      <script>
      var ticks;
      var mytimer;

      function start() {
      ticks = Number(prompt("where do you want to start a countdown, min 1 max 10")) + 1;
      if (ticks > 11) {
      ticks = Number(prompt("Skriv inn på nytt, tallet må være mellom 3-10")) + 1;
      }
      else if (ticks < 1) {
      ticks = Number(prompt("Try again, The number must be between 1-10")) + 1;
      }
      mytimer = setInterval(tick, 1000)

      }

      function tick() {
      ticks--;
      document.getElementById("p").innerHTML = "Tick nr. " + ticks + "<br />";

      if (ticks === 1) {
      clearInterval(mytimer);
      document.write("Done!");
      }
      }
      </script>









      share|improve this question














      so i am trying to make a tick system, where i a user can pick a number from 1-10 and there will start a countdown from the number that the user picks to 0. The problem is that when a user picks number 12 in prompt, it doesnt allow him/her to continue, but when they try again it allows them.



      html:



       <button onclick=start()>Countdown</button>
      <p id="p">


      scirpt:



      <script>
      var ticks;
      var mytimer;

      function start() {
      ticks = Number(prompt("where do you want to start a countdown, min 1 max 10")) + 1;
      if (ticks > 11) {
      ticks = Number(prompt("Skriv inn på nytt, tallet må være mellom 3-10")) + 1;
      }
      else if (ticks < 1) {
      ticks = Number(prompt("Try again, The number must be between 1-10")) + 1;
      }
      mytimer = setInterval(tick, 1000)

      }

      function tick() {
      ticks--;
      document.getElementById("p").innerHTML = "Tick nr. " + ticks + "<br />";

      if (ticks === 1) {
      clearInterval(mytimer);
      document.write("Done!");
      }
      }
      </script>






      javascript if-statement






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 7:37









      Raahim KhanRaahim Khan

      164




      164
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Untill you are not getting any number between 1 - 10, you may try calling same method again as follow:



          <script>
          var ticks;
          var mytimer;

          function start() {
          ticks = Number(prompt("where do you want to start a countdown, min 1 max 10")) + 1;
          if (ticks > 10) {
          start();
          }
          else if (ticks < 1) {
          start();
          }
          mytimer = setInterval(tick, 1000)

          }

          function tick() {
          ticks--;
          document.getElementById("p").innerHTML = "Tick nr. " + ticks + "<br />";

          if (ticks === 1) {
          clearInterval(mytimer);
          document.write("Done!");
          }
          }
          </script>





          share|improve this answer































            0














            The solution is simple. When you first time enter a value bigger than 11 if (ticks > 11) { statement catches it and then shows new prompt. If you again enter a value bigger than 11, there is no if statement to catch it. If you run the start function again when a faulty value entered, you can fix this problem.






            share|improve this answer
























            • ah yes, that makes sense, but do you have any examples on how i can recall the function, is it possible to keep on calling the function in an if statement.

              – Raahim Khan
              Nov 22 '18 at 9:49











            • You can do it like in @Bishal's answer ----> if (ticks > 11) { start();}

              – Rıdvan Sumset
              Nov 22 '18 at 10:21












            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425980%2ftrying-to-make-nr-restriction-1-10-but-prompt-allows-users-to-pick-13%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Untill you are not getting any number between 1 - 10, you may try calling same method again as follow:



            <script>
            var ticks;
            var mytimer;

            function start() {
            ticks = Number(prompt("where do you want to start a countdown, min 1 max 10")) + 1;
            if (ticks > 10) {
            start();
            }
            else if (ticks < 1) {
            start();
            }
            mytimer = setInterval(tick, 1000)

            }

            function tick() {
            ticks--;
            document.getElementById("p").innerHTML = "Tick nr. " + ticks + "<br />";

            if (ticks === 1) {
            clearInterval(mytimer);
            document.write("Done!");
            }
            }
            </script>





            share|improve this answer




























              0














              Untill you are not getting any number between 1 - 10, you may try calling same method again as follow:



              <script>
              var ticks;
              var mytimer;

              function start() {
              ticks = Number(prompt("where do you want to start a countdown, min 1 max 10")) + 1;
              if (ticks > 10) {
              start();
              }
              else if (ticks < 1) {
              start();
              }
              mytimer = setInterval(tick, 1000)

              }

              function tick() {
              ticks--;
              document.getElementById("p").innerHTML = "Tick nr. " + ticks + "<br />";

              if (ticks === 1) {
              clearInterval(mytimer);
              document.write("Done!");
              }
              }
              </script>





              share|improve this answer


























                0












                0








                0







                Untill you are not getting any number between 1 - 10, you may try calling same method again as follow:



                <script>
                var ticks;
                var mytimer;

                function start() {
                ticks = Number(prompt("where do you want to start a countdown, min 1 max 10")) + 1;
                if (ticks > 10) {
                start();
                }
                else if (ticks < 1) {
                start();
                }
                mytimer = setInterval(tick, 1000)

                }

                function tick() {
                ticks--;
                document.getElementById("p").innerHTML = "Tick nr. " + ticks + "<br />";

                if (ticks === 1) {
                clearInterval(mytimer);
                document.write("Done!");
                }
                }
                </script>





                share|improve this answer













                Untill you are not getting any number between 1 - 10, you may try calling same method again as follow:



                <script>
                var ticks;
                var mytimer;

                function start() {
                ticks = Number(prompt("where do you want to start a countdown, min 1 max 10")) + 1;
                if (ticks > 10) {
                start();
                }
                else if (ticks < 1) {
                start();
                }
                mytimer = setInterval(tick, 1000)

                }

                function tick() {
                ticks--;
                document.getElementById("p").innerHTML = "Tick nr. " + ticks + "<br />";

                if (ticks === 1) {
                clearInterval(mytimer);
                document.write("Done!");
                }
                }
                </script>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 7:44









                Bishal GautamBishal Gautam

                855519




                855519

























                    0














                    The solution is simple. When you first time enter a value bigger than 11 if (ticks > 11) { statement catches it and then shows new prompt. If you again enter a value bigger than 11, there is no if statement to catch it. If you run the start function again when a faulty value entered, you can fix this problem.






                    share|improve this answer
























                    • ah yes, that makes sense, but do you have any examples on how i can recall the function, is it possible to keep on calling the function in an if statement.

                      – Raahim Khan
                      Nov 22 '18 at 9:49











                    • You can do it like in @Bishal's answer ----> if (ticks > 11) { start();}

                      – Rıdvan Sumset
                      Nov 22 '18 at 10:21
















                    0














                    The solution is simple. When you first time enter a value bigger than 11 if (ticks > 11) { statement catches it and then shows new prompt. If you again enter a value bigger than 11, there is no if statement to catch it. If you run the start function again when a faulty value entered, you can fix this problem.






                    share|improve this answer
























                    • ah yes, that makes sense, but do you have any examples on how i can recall the function, is it possible to keep on calling the function in an if statement.

                      – Raahim Khan
                      Nov 22 '18 at 9:49











                    • You can do it like in @Bishal's answer ----> if (ticks > 11) { start();}

                      – Rıdvan Sumset
                      Nov 22 '18 at 10:21














                    0












                    0








                    0







                    The solution is simple. When you first time enter a value bigger than 11 if (ticks > 11) { statement catches it and then shows new prompt. If you again enter a value bigger than 11, there is no if statement to catch it. If you run the start function again when a faulty value entered, you can fix this problem.






                    share|improve this answer













                    The solution is simple. When you first time enter a value bigger than 11 if (ticks > 11) { statement catches it and then shows new prompt. If you again enter a value bigger than 11, there is no if statement to catch it. If you run the start function again when a faulty value entered, you can fix this problem.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 22 '18 at 7:57









                    Rıdvan SumsetRıdvan Sumset

                    1257




                    1257













                    • ah yes, that makes sense, but do you have any examples on how i can recall the function, is it possible to keep on calling the function in an if statement.

                      – Raahim Khan
                      Nov 22 '18 at 9:49











                    • You can do it like in @Bishal's answer ----> if (ticks > 11) { start();}

                      – Rıdvan Sumset
                      Nov 22 '18 at 10:21



















                    • ah yes, that makes sense, but do you have any examples on how i can recall the function, is it possible to keep on calling the function in an if statement.

                      – Raahim Khan
                      Nov 22 '18 at 9:49











                    • You can do it like in @Bishal's answer ----> if (ticks > 11) { start();}

                      – Rıdvan Sumset
                      Nov 22 '18 at 10:21

















                    ah yes, that makes sense, but do you have any examples on how i can recall the function, is it possible to keep on calling the function in an if statement.

                    – Raahim Khan
                    Nov 22 '18 at 9:49





                    ah yes, that makes sense, but do you have any examples on how i can recall the function, is it possible to keep on calling the function in an if statement.

                    – Raahim Khan
                    Nov 22 '18 at 9:49













                    You can do it like in @Bishal's answer ----> if (ticks > 11) { start();}

                    – Rıdvan Sumset
                    Nov 22 '18 at 10:21





                    You can do it like in @Bishal's answer ----> if (ticks > 11) { start();}

                    – Rıdvan Sumset
                    Nov 22 '18 at 10:21


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425980%2ftrying-to-make-nr-restriction-1-10-but-prompt-allows-users-to-pick-13%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                    ComboBox Display Member on multiple fields

                    Is it possible to collect Nectar points via Trainline?