Table-4 Not
Not !
- The boolean "not" operation inverts true and false
- Takes the "opposite" of whatever is inside in the parentheses
- Syntax:
!(expression)
- The exclamation mark (!) signifies not
- Parentheses marks off what we want to "not"
- Expression - anything that can go in an if statement!
- Boolean logic, startsWith/endsWith, <, >, ==
- Works on part of a boolean logic statement too
- Example:
if (row.getField("gender") == "girl" &&
!(row.getField("rank") > 10))
Not Code Experiments
Experiments to try:
- 1. girl names starting with "A" (no "nots" in this one)
- 2. girl names not starting with "A"
- 3. names starting with "A" and not ending with "y"
- 4. names starting with "A" and ending with "y" and not equal to "Abbey"
Experiment solution code:
If logic inside the loop:
// 1
if (row.getField("name").startsWith("A") &&
row.getField("gender") == "girl") {
print(row);
}
// 2
if (!(row.getField("name").startsWith("A")) &&
row.getField("gender") == "girl") {
print(row);
}
// 3
if (row.getField("name").startsWith("A") &&
!(row.getField("name").endsWith("y"))) {
print(row);
}
// 4
if (row.getField("name").startsWith("A") &&
row.getField("name").endsWith("y") &&
!(row.getField("name") == "Abbey")) {
print(row);
}
> exercises