I\'m calling a Javascript window.prompt()
and prompting the user to submit a variable which I compare to another variable (a very basic password protection). Th
prompt returns a string if the user presses OK
(''
being with no value submitted). If the user pressed Cancel
, null
is returned. All you need to do is check whether the value is null
:
function doSomething() {
var input;
input = prompt('Do something?');
if (input === null) {
return; //break out of the function early
}
switch (input) {
case 'fun':
doFun();
break;
case 'boring':
beBoring();
break;
}
}