Problem Parsing && and || Operators into Natural Language


In this code

var answer = prompt("Are we there yet?");

while (!answer.includes("yes") && !answer.includes("yeah")) {
	answer = prompt("Are we there yet?");

alert("YAY!! WE MADE IT!!!");

why’s it && and not || – why use logical-and and not logical-or – since in natural languages we say “while the answer doesn’t include either ‘yes’ or ‘yeah’”…but that doesn’t work in JavaScript.

As-is, the code seems to parse into natural languages as “while the answer doesn’t include ‘yes’ and ‘yeah’” – which is what works in JavaScript!

Please help me think this through. I don’t know why I have such a “mental block” about it…thanks!


I mean, I know that “functionally” it means

the two cases where the operation is to be performed are
while the answer is X
while the answer is Y

but isn’t there a way to put that into colloquial English or is that just problematic and therefore I shouldn’t try to understand JavaScript the way I would translate something non-English into English first in order to understand it?

Or should I just accept that it’s an idiom in JavaScript, a kind of “logical idiom,” so to speak?

I should note, FWIW, that I sometimes have issues like this in mathematics, too – so maybe it’s just a “cognitive” thing with me, like vague and minor autism or something! But I try translating things into plain everyday speech and perhaps that’s a bad habit since if ordinary speech were at all adequate, there wouldn’t be a need for math or any other “logical language!”


You can write that with OR instead. You would of course have to change other things as well or it would mean something else.
Avoid more than one NOT, it’s difficult to keep track.
There’s also nothing stopping you from using arrays or other data structures and checking for things like “at least one” or “all” or “none”

If you can think the thought then you can probably program it too, you probably didn’t think through what you meant in natural language, or you’d be able to describe it as such in code as well.

Human thinking patterns is what you should be aiming for. That’s what programming languages are for, bringing computer instructions closer to humans.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.