Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q936 How can a function return true first time, then false, then true....?

You are here: irt.org | FAQ | JavaScript | Function | Q936 [ previous next ]

Try:

<script language="JavaScript"><!--
var bool=false;
function not() { return (bool = !bool); }

alert(not());
alert(not());
alert(not());
alert(not());
//--></script>

Although you don't really need a function for this, just:

<script language="JavaScript"><!--
var bool=false;

alert(bool = !bool);
alert(bool = !bool);
alert(bool = !bool);
alert(bool = !bool);
//--></script>

©2018 Martin Webb