javascript - How to make the code shorter with keeping loop? -


how make code shorter keeping loop?

    var age = prompt("what age");      (var i=18; i<=age ; i++){         alert ("welcome");      break     }      (var i=18; i>age ; i++){         alert ("sorry, under 18");     break      } 

an awful lot of example code seems wrong. using loops should using conditionals , loop conditions not trigger until numeric overflow, except unconditionally break loops anyway (which further suggests want using conditionals, not loop).

what want this:

if( age >= 18) {   alert("welcome"); } else {   alert("sorry, under 18"); } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -