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
Post a Comment