Can you add “and” &“or” to if statements when coding? if so can you guys give a simple code for reference, Im extremely new to all of this and any advice would be welcomed. thanksss
Yes you can do Or, but not And. The only way to do that is
if (something===“e”||something===“stop”)
{something()}
The || is the code for the Or
well there are no “and” or “or” in javascript, and they can’t just add those in because they use javascript to run javascript code they didn’t make a javascript interpreter it’s javascript so they wouldn’t have to make an interpreter because of javascript i
You can do “And” by using “&&
”
Here’s an example:
if ( ... === " " && ... === " " ){
}
That’s true, we can’t add an “and” or an “or,” since js isn’t english. Instead we use “&&
” or “||
”
Just to add in here and summarize.
Wick Editor uses JavaScript! In JavaScript we write “and” with two ampersands &&
and “or” with two long bar symbols ||
So an if statement can look like this.
if (thingOne && thingTwo) { }
// This is “and”
or
if (thingOne || thingTwo) { }
// This is “or”
or
if (thingOne && thingTwo || thing three) { }
// This is both!
I believe the && operator is prioritized above ||. if you wanted to check the || first, use the () to group thingTwo and thingThree.
if (thingOne && (thingTwo || thingThree)) { } // this checks thingTwo and thingThree before checking if it and thingOne are true
That’s just a theory a, I believe the && operator is prioritized above ||. if you wanted to check the || first, use the () to group thingTwo and thingThree…THEORY!!!(;