PDA

View Full Version : Why dont my boolean expression work in While loop? Please help


Broucheek
02-12-2008, 08:52 AM
Hello there,

I wrote the following code. However it doesnt work. Can anyone tell me why. If i delete the first second expression and leave just the one it works. It seems that something in the 2 expressions is incorrect but i have no idea what.

Thank you

Code is;

<HEAD>
<TITLE>
While loop
</TITLE>
<SCRIPT LANGUAGE = "JavaScript">


var pass;

pass = window.prompt('Please enter your password', ' ');
while ((pass != 'truck') || (pass != 'orange'))
{
pass = window.prompt('Please enter either orange or truck', ' ');
};
document.write('thank you');

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

Kor
02-12-2008, 09:03 AM
Should be

while ((pass != 'truck') && (pass != 'orange'))

because true||false or false||true returns always true