Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Function | Q936 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.