javascript prompt blank
I'm not sure what you want to achieve, but here is a code that will loop until you fill up prompt field.
do { var str = prompt(":");} while(!str || str.length == 0);alert(str);
Some more about your code:
I've had a loot of ideas what you might wanted to achieve, but you probably trying to make klantnaam2 a function that will display text "Sorry wat is uw naam?" and klantnaam variable content.
My guess is:
var klantnaam2 = function(){ alert("Sorry wat is uw naam? " + klantnaam);}
Second thing, your else if, it has 2 conditions but actualy only one is variable, if(false) will be never fulfilled. You probably want to have:
else if (klantnaam == null || klantnaam == false)
But to check if string is empty you just need to check its length. You can fist check if it's not null, but prompt will return string, so it's not necessary.
To call function you need to use () operator, so instead of klantnaam; you should use:
klantnaam();
My last guess is http://jsfiddle.net/9nvsLugq/
function klantnaam2(){ alert("Sorry wat is uw naam?"); klantnaam();}function klantnaam(){ var str = prompt("vul hier uw naam in"); if(str == "") { klantnaam2(); } else if(str == null || str == false) { klantnaam2(); }}klantnaam();
Also you can bring all if's together into one, excluding checking for false
if(str == null || str == ""){ klantnaam2();}
and use do-while loop instead of functions. And you will end up with a code I pasted on top of this post.
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