Using Coffeescript, I am trying to set conditionals for setting a fillColor on a graph plot for two variables; lastVisibility and curr_visibility. Something is not right with my syntax. Any suggestions
for set in datasets
line.push
data: set,
lines:
show: true
fill: true
opacity: 0.7
fillColor: if lastVisibilty == 0 & curr_visibility == 0
then "#C90E30"
else lastVisibilty == 0 & curr_visibility == 1
then "#439C32"
else lastVisibilty == 1 & curr_visibility == 0
then "#C90E30"
else
"#439C32"
There are lots of problems here:
You only use then when you're using a one-liner such as a = if b then c else d, if you're using the multi-line form of if then you don't use thens.
You have multiple else branches where you mean else if.
& and && are different things, & is a bit-wise operator, && is the logical conjunction you're looking for.
You need to be very careful and consistent with your indentation.
Applying those adjustments to your code you get:
for set in datasets
line.push
data: set,
lines:
show: true
fill: true
opacity: 0.7
fillColor: if lastVisibilty == 0 && curr_visibility == 0
"#C90E30"
else if lastVisibilty == 0 && curr_visibility == 1
"#439C32"
else if lastVisibilty == 1 && curr_visibility == 0
"#C90E30"
else
"#439C32"
However, the conditional logic inside your loop doesn't depend on set (i.e. is loop invariant) so you should factor that out:
fillColor = if lastVisibilty == 0 && curr_visibility == 0
"#C90E30"
else if lastVisibilty == 0 && curr_visibility == 1
"#439C32"
else if lastVisibilty == 1 && curr_visibility == 0
"#C90E30"
else
"#439C32"
for set in datasets
line.push
data: set,
lines:
show: true
fill: true
opacity: 0.7
fillColor: fillColor
Or better, push all the invariant stuff outside the loop to further clarify the code:
fillColor = if lastVisibilty == 0 && curr_visibility == 0
"#C90E30"
else if lastVisibilty == 0 && curr_visibility == 1
"#439C32"
else if lastVisibilty == 1 && curr_visibility == 0
"#C90E30"
else
"#439C32"
lines =
show: true
fill: true
opacity: 0.7
fillColor: fillColor
for set in datasets
line.push
data: set,
lines: lines
Or, since a for-loop is an expression, you could say:
fillColor = if lastVisibilty == 0 && curr_visibility == 0
"#C90E30"
else if lastVisibilty == 0 && curr_visibility == 1
"#439C32"
else if lastVisibilty == 1 && curr_visibility == 0
"#C90E30"
else
"#439C32"
lines =
show: true
fill: true
opacity: 0.7
fillColor: fillColor
line = ({ data: set, lines: line } for set in datasets)
Assuming that line is empty before your loop of course; if it isn't then you could use Array.prototype.concat:
line = line.concat({data: set, lines: line } for set in datasets)
to append the loop's data to line.
Related
With this script I can exclude to insert the same value column in Google Sheet for maximum 100 times.
But I am trying to exclude (with if statement) some values from this script, in particular the date "25/12/2022" and the date "12/01/2012".
How could I proceed?
function onEdit(e) {
var r = e.range;
var s = r.getSheet();
if (s.getName() === 'New Rise 2022' && r.getColumn() === 27) {
var newValue = r.getDisplayValue();
if (newValue == "") return;
var count = s.getRange('AA1:AA').getDisplayValues().filter(([a]) => a === newValue).length;
if (count > 99) {
r.setValue(e.oldValue);
SpreadsheetApp.flush();
SpreadsheetApp.getUi().alert('Questa data è stata già inserita 100 volte');
}
}
}
Update:
function onEdit(e) {
var r = e.range;
var s = r.getSheet();
if (s.getName() === 'New Rise 2022' && r.getColumn() === 27) {
var newValue = r.getDisplayValue();
if (newValue == "") return;
var count = s.getRange('AA1:AA').getDisplayValues().filter(([a]) => a === newValue).length;
if (count > 99 || e.range.getDisplayValue() == "25/12/2012" || e.range.getDisplayValue() == "12/01/2012") {
r.setValue(e.oldValue);
r.setNumberFormat('dd/mm/YYYY');
SpreadsheetApp.flush();
SpreadsheetApp.getUi().alert('Questa data è stata già inserita 100 volte');
}
}
}
How about this?
function onEdit(e) {
const sh = e.range.getSheet();
const x = ["25/12/2022","12/01/2012"];
const idx = x.indexOf(e.value);
if (sh.getName() === 'New Rise 2022' && e.range.columnStart == 27 && e.value && !~idx) {
var count = sh.getRange('AA1:AA' + sh.getLastRow()).getDisplayValues().flat().filter(e => e == e.value).length;
if (count > 99) {
e.range.setValue(e.oldValue);
}
}
}
You can get the newly entered display value and compare it against the "forbidden" values
Therefore, retrieve the latest modified cell with e.range:
...
if (count > 99 || e.range.getDisplayValue() == "25/12/2022" || e.range.getDisplayValue() == "12/01/2012") {
...
}
...
Note:
I understood that what you are interested in is the displayed value (date in this case), but depending on your date formatting the display value will be different from the value you typed in.
If it is the typed in value you are after, you can retrieve it with e.value:
...
console.log("e.value: " + e.value)
console.log("e.range.getDisplayValue(): " + e.range.getDisplayValue())
if (count > 99 || e.value == "25/12/2022" || e.value == "12/01/2012") {
...
}
...
References:
Event Objects
getDisplayValue()
UPDATE:
If you have problems with number formatting you can use the method setNumberFormat().
Modify your code block in the if statement to
r.setValue(e.oldValue);
r.setNumberFormat('dd/mm/YYYY');
I have this function that changes the centerLocation of the map, this causes the map to animate over all the locations. The lat and longitude are being incremented and decremented and repeats with the use of a timer. However I am currently trying to pause the timer. I have tried multiple methods and can't seem to get the timer to pause for a few seconds and resume. The only thing that works is using sleep, but that causes the whole UI to pause. This 'move' function is updating an #State CLLocationCoordinate's lat and long. This method is called in .onAppear().
timer.fire() does not work
I also tried something like this:
timer.invalidate()
DispatchQueue.main.asyncAfter(deadline: .now() + 5.00) {
timer.fire()
}
Code above does not work
func moveRegion() {
var currentLatitude = region.center.latitude
var currentLongitude = region.center.longitude
let increment = 0.25
var southAmerica = false
var europe = false
var australia = false
var america = true
Timer.scheduledTimer(withTimeInterval: (1.0/30.0), repeats: true) { (timer) in
//AMERICA CORD 37.0000, -95.000
//MOVING TO SOUTH AMERICA
//SOUTH AMERICA CORD -33.000, -70.000
if (america == true && southAmerica == false && europe == false && australia == false){
if (currentLatitude <= -33.000 && currentLatitude >= 37.0000 || currentLongitude <= -70.0000 && currentLongitude >= -95.0000 || currentLongitude >= -101.69999999998991) {
currentLatitude -= increment
currentLatitude -= increment
currentLatitude -= increment
if currentLongitude < -70.00 {
currentLongitude += increment
}
}
if (currentLatitude == -38.15000000000002 || currentLatitude <= -38.150000000000006 && currentLongitude <= -69.95000000000142){
// sleep(5), works but pauses whole UI
timer.invalidate()
Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { pauseTimer in
timer.fire()
print(timer.isValid)
}
southAmerica = true
australia = false
america = false
europe = false
}
}
//MOVING TO EUROPE
//Europe CORD 48.000, 15.000
//if (currentLongitude > -74.00 && currentLongitude < -4.00)
if (southAmerica == true && australia == false && america == false && europe == false ){
if (currentLatitude > -39.000 && currentLatitude < 55.000 || currentLongitude > -70.00 && currentLongitude < 16.000) {
currentLongitude += increment
currentLongitude += increment
currentLatitude += increment
currentLatitude += increment
}
if (currentLatitude >= 48.04999999999936 || currentLatitude == 48.04999999999937 && currentLongitude <= 16.249999999996835){
sleep(5)
europe = true
southAmerica = false
australia = false
america = false
}
}
//MOVING TO AUSTRALIA
//AUSTRALIA CORD -36.000, 133.000
if (europe == true && southAmerica == false && australia == false && america == false){
if (currentLongitude > 9.00 && currentLongitude < 133.000) {
currentLongitude += increment
currentLongitude += increment
currentLongitude += increment
}
if (currentLatitude >= -38.000 && currentLatitude <= 49.0000){
currentLatitude -= increment
currentLatitude -= increment
}
if (currentLatitude <= -37.05000000000008 && currentLongitude >= 132.04999999999274){
sleep(5)
australia = true
southAmerica = false
europe = false
america = false
}
}
//MOVING TO AMERIA
if (australia == true && southAmerica == false && america == false && europe == false){
if (currentLongitude < 179.55){
currentLongitude += increment
currentLongitude += increment
if (currentLongitude > 179.500){
currentLongitude = -179.000
}
}
if (currentLongitude > -95.100) {
currentLongitude += increment
currentLongitude += increment
}
if (currentLatitude >= -39.000 && currentLatitude <= 37.0000){
currentLatitude += increment
currentLatitude += increment
}
if (currentLatitude >= 37.04999999999998 && currentLongitude >= -95.100){
australia = false
southAmerica = false
europe = false
america = true
currentLatitude = 37.0000
currentLongitude = -95.000
sleep(5)
}
}
region.center.longitude = currentLongitude
region.center.latitude = currentLatitude
centerLocation.latitude = currentLatitude
centerLocation.longitude = currentLongitude
}
}
Then in the view
var body: some View {
SwiftUIMapView(centerLocation: $centerLocation)
.onAppear {
DispatchQueue.main.async {
moveRegion()
}
}
}
Here is the full code bellow:
import SwiftUI
import MapKit
struct MapView: View {
var timer = Timer()
//Start Location of the Map
#State var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 37.0000, longitude: -95.000),
span: MKCoordinateSpan(latitudeDelta: 40, longitudeDelta: 40)
)
#State var centerLocation = CLLocationCoordinate2D()
func moveRegion() {
var currentLatitude = region.center.latitude
var currentLongitude = region.center.longitude
let increment = 0.25
var southAmerica = false
var europe = false
var australia = false
var america = true
Timer.scheduledTimer(withTimeInterval: (1.0/30.0), repeats: true) { (timer) in
//AMERICA CORD 37.0000, -95.000
//MOVING TO SOUTH AMERICA
//SOUTH AMERICA CORD -33.000, -70.000
if (america == true && southAmerica == false && europe == false && australia == false){
if (currentLatitude <= -33.000 && currentLatitude >= 37.0000 || currentLongitude <= -70.0000 && currentLongitude >= -95.0000 || currentLongitude >= -101.69999999998991) {
currentLatitude -= increment
currentLatitude -= increment
currentLatitude -= increment
if currentLongitude < -70.00 {
currentLongitude += increment
}
}
if (currentLatitude == -38.15000000000002 || currentLatitude <= -38.150000000000006 && currentLongitude <= -69.95000000000142){
// sleep(5), works but pauses whole UI
timer.invalidate()
Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { pauseTimer in
timer.fire()
print(timer.isValid)
}
southAmerica = true
australia = false
america = false
europe = false
}
}
//MOVING TO EUROPE
//Europe CORD 48.000, 15.000
//if (currentLongitude > -74.00 && currentLongitude < -4.00)
if (southAmerica == true && australia == false && america == false && europe == false ){
if (currentLatitude > -39.000 && currentLatitude < 55.000 || currentLongitude > -70.00 && currentLongitude < 16.000) {
currentLongitude += increment
currentLongitude += increment
currentLatitude += increment
currentLatitude += increment
}
if (currentLatitude >= 48.04999999999936 || currentLatitude == 48.04999999999937 && currentLongitude <= 16.249999999996835){
sleep(5)
europe = true
southAmerica = false
australia = false
america = false
}
}
//MOVING TO AUSTRALIA
//AUSTRALIA CORD -36.000, 133.000
if (europe == true && southAmerica == false && australia == false && america == false){
if (currentLongitude > 9.00 && currentLongitude < 133.000) {
currentLongitude += increment
currentLongitude += increment
currentLongitude += increment
}
if (currentLatitude >= -38.000 && currentLatitude <= 49.0000){
currentLatitude -= increment
currentLatitude -= increment
}
if (currentLatitude <= -37.05000000000008 && currentLongitude >= 132.04999999999274){
sleep(5)
australia = true
southAmerica = false
europe = false
america = false
}
}
//MOVING TO AMERIA
if (australia == true && southAmerica == false && america == false && europe == false){
if (currentLongitude < 179.55){
currentLongitude += increment
currentLongitude += increment
if (currentLongitude > 179.500){
currentLongitude = -179.000
}
}
if (currentLongitude > -95.100) {
currentLongitude += increment
currentLongitude += increment
}
if (currentLatitude >= -39.000 && currentLatitude <= 37.0000){
currentLatitude += increment
currentLatitude += increment
}
if (currentLatitude >= 37.04999999999998 && currentLongitude >= -95.100){
australia = false
southAmerica = false
europe = false
america = true
currentLatitude = 37.0000
currentLongitude = -95.000
sleep(5)
}
}
region.center.longitude = currentLongitude
region.center.latitude = currentLatitude
centerLocation.latitude = currentLatitude
centerLocation.longitude = currentLongitude
}
}
var body: some View {
SwiftUIMapView(centerLocation: $centerLocation)
.onAppear {
DispatchQueue.main.async {
moveRegion()
}
}
}
}
Any help is greatly appreciated thank you!
Using Timer for this and trying to invalidate, re-fire, etc is going to be difficult (or in fact, impossible -- Timer can't re-fire once it is invalidated). But, this seemed like a pretty good opportunity to user Timer in a publisher with Combine and then just give it some intervals to wait out -- the publisher still fires events, it just doesn't do anything with them until the next wait interval has been hit:
struct ContentView : View {
var body: some View {
MapView()
}
}
class LocationManager : ObservableObject {
#Published var centerLocation = CLLocationCoordinate2D()
#Published var region : MKCoordinateRegion
private var currentLatitude : CLLocationDegrees
private var currentLongitude : CLLocationDegrees
init() {
let region = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 37.0000, longitude: -95.000),
span: MKCoordinateSpan(latitudeDelta: 40, longitudeDelta: 40)
)
currentLatitude = region.center.latitude
currentLongitude = region.center.longitude
self.region = region
}
private var cancellable : AnyCancellable?
private var waitUntil : Date?
private var currentFireDate : Date = Date()
func start() {
cancellable = Timer.publish(every: (1.0/30.0), on: .main, in: .default)
.autoconnect()
.sink { val in
if let waitUntil = self.waitUntil {
if val < waitUntil {
return
} else {
self.waitUntil = nil
}
}
self.currentFireDate = val
self.moveRegion()
}
}
let increment = 0.25
var southAmerica = false
var europe = false
var australia = false
var america = true
func moveRegion() {
//AMERICA CORD 37.0000, -95.000
//MOVING TO SOUTH AMERICA
//SOUTH AMERICA CORD -33.000, -70.000
if (america == true && southAmerica == false && europe == false && australia == false){
if (currentLatitude <= -33.000 && currentLatitude >= 37.0000 || currentLongitude <= -70.0000 && currentLongitude >= -95.0000 || currentLongitude >= -101.69999999998991) {
currentLatitude -= increment
currentLatitude -= increment
currentLatitude -= increment
if currentLongitude < -70.00 {
currentLongitude += increment
}
}
if (currentLatitude == -38.15000000000002 || currentLatitude <= -38.150000000000006 && currentLongitude <= -69.95000000000142){
waitUntil = currentFireDate.addingTimeInterval(5.0)
southAmerica = true
australia = false
america = false
europe = false
}
}
//MOVING TO EUROPE
//Europe CORD 48.000, 15.000
//if (currentLongitude > -74.00 && currentLongitude < -4.00)
if (southAmerica == true && australia == false && america == false && europe == false ){
if (currentLatitude > -39.000 && currentLatitude < 55.000 || currentLongitude > -70.00 && currentLongitude < 16.000) {
currentLongitude += increment
currentLongitude += increment
currentLatitude += increment
currentLatitude += increment
}
if (currentLatitude >= 48.04999999999936 || currentLatitude == 48.04999999999937 && currentLongitude <= 16.249999999996835){
waitUntil = currentFireDate.addingTimeInterval(5.0)
europe = true
southAmerica = false
australia = false
america = false
}
}
//MOVING TO AUSTRALIA
//AUSTRALIA CORD -36.000, 133.000
if (europe == true && southAmerica == false && australia == false && america == false){
if (currentLongitude > 9.00 && currentLongitude < 133.000) {
currentLongitude += increment
currentLongitude += increment
currentLongitude += increment
}
if (currentLatitude >= -38.000 && currentLatitude <= 49.0000){
currentLatitude -= increment
currentLatitude -= increment
}
if (currentLatitude <= -37.05000000000008 && currentLongitude >= 132.04999999999274){
waitUntil = currentFireDate.addingTimeInterval(5.0)
australia = true
southAmerica = false
europe = false
america = false
}
}
//MOVING TO AMERIA
if (australia == true && southAmerica == false && america == false && europe == false){
if (currentLongitude < 179.55){
currentLongitude += increment
currentLongitude += increment
if (currentLongitude > 179.500){
currentLongitude = -179.000
}
}
if (currentLongitude > -95.100) {
currentLongitude += increment
currentLongitude += increment
}
if (currentLatitude >= -39.000 && currentLatitude <= 37.0000){
currentLatitude += increment
currentLatitude += increment
}
if (currentLatitude >= 37.04999999999998 && currentLongitude >= -95.100){
australia = false
southAmerica = false
europe = false
america = true
currentLatitude = 37.0000
currentLongitude = -95.000
waitUntil = currentFireDate.addingTimeInterval(5.0)
}
}
region.center.longitude = currentLongitude
region.center.latitude = currentLatitude
centerLocation.latitude = currentLatitude
centerLocation.longitude = currentLongitude
}
}
struct MapView: View {
#ObservedObject var locationManager = LocationManager()
var body: some View {
SwiftUIMapView(centerLocation: $locationManager.centerLocation)
.onAppear {
locationManager.start()
}
}
}
struct SwiftUIMapView : UIViewRepresentable {
#Binding var centerLocation : CLLocationCoordinate2D
func makeUIView(context: Context) -> MKMapView {
let mapView = MKMapView()
return mapView
}
func updateUIView(_ uiView: MKMapView, context: Context) {
uiView.centerCoordinate = centerLocation
}
}
Here's what happens:
Location is now controlled by an ObservableObject LocationManager
On start(), a publisher that fires once every 1/30 seconds is fired
On each fire, it calls moveLocation()
When moveLocation wants to pause, it sets waitUntil 5 seconds ahead of the last date of the publisher firing
If the the publisher gets fired and the time is before waitUntil, it just returns and waits for the next fire
I'm trying to take a series of numbers from a text file and based on the numbers define a new variable. When I print SettingsArray i get the following:
[10, 25, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0.02, 0.002, 0, 1, 0, 0, 0, 1, 1, 1, 25, 500, 0, 1, 250, 250, 250, 500, 500, 500, 10, 10, 10, 200, 200, 200]
Which are the numbers I'm looking for, but for some reason, when checking the If statements, all of the SettingsArray elements look something like this:
[2] String class name = _TtC10Foundation15_NSOpaqueString
Which obviously don't meet any of the conditions, why are the array elements garbled when checking the If statements?
let file = String(contentsOfFile: "/Users/UserGoesHere/Documents/Settings.txt", encoding: NSUTF8StringEncoding, error: nil)!
var SettingsArray = split(file) {$0 == ","}
var StepPortInvert = ""
if SettingsArray[2] == "1" && SettingsArray[3] == "1" && SettingsArray[4] == "1" {
var StepPortInvert = "00000000"
}
if SettingsArray[2] == "0" && SettingsArray[3] == "1" && SettingsArray[4] == "1" {
var StepPortInvert = "00000001"
}
if SettingsArray[2] == "1" && SettingsArray[3] == "0" && SettingsArray[4] == "1" {
var StepPortInvert = "00000010"
}
You just have to declare StepPortInvert once. BTW 2,3,4 = "1, 0, 0"
let file = String(contentsOfFile: "/Users/UserGoesHere/Documents/Settings.txt", encoding: NSUTF8StringEncoding, error: nil)!
var SettingsArray = split(file) {$0 == ","}
var StepPortInvert = ""
if SettingsArray[2] == "1" && SettingsArray[3] == "1" && SettingsArray[4] == "1" {
StepPortInvert = "00000000"
}
if SettingsArray[2] == "0" && SettingsArray[3] == "1" && SettingsArray[4] == "1" {
StepPortInvert = "00000001"
}
if SettingsArray[2] == "1" && SettingsArray[3] == "0" && SettingsArray[4] == "1" {
StepPortInvert = "00000010"
}
I have a little problem with if statement as it populates only last elseif
%%[IF #Add3 == "Y" AND #Add4 == "Y" AND #Add5 == "N" THEN
SET #WhichNom1 = "1"
SET #WhichNom2 = "2"
ELSEIF #Add3 == "Y" AND #Add4 == "N" AND #Add5 == "Y" THEN
SET #WhichNom1 = "1"
SET #WhichNom2 = "3"
ELSEIF #Add3 == "N" AND #Add4 == "Y" AND #Add5 == "Y" THEN
SET #WhichNom1 = "1"
SET #WhichNom2 = "3"
]%%
#WhichNom1
#WhichNom2
%%[ENDIF]%%
The code above will display two variables when the last ELSEIF is TRUE. What do I need to do to check 3 statements and display WhichNom1 and WhichNom2 for every scenario?
You're only printing the variables if the last elseif is true.
Move them like this:
...
ELSEIF #Add3 == "N" AND #Add4 == "Y" AND #Add5 == "Y" THEN
SET #WhichNom1 = "1"
SET #WhichNom2 = "3"
]%%
%%[ENDIF]%%
#WhichNom1
#WhichNom2
So they're outside the IF/ELSEIF. That way they'll always be printed, but the variables will be set differently based on the clauses.
EDIT:
If you only want the variables printed if one of the statements is true, then you would (as you have mentioned) need to print them within the if statement, OR you could:
SET #WhichNom1 = ""
SET #WhichNom2 = ""
before the if statements, then after them do:
IF #WhichNom1 != "" THEN #WhichNom1
IF #WhichNom2 != "" THEN #WhichNom2
so you only print them if they've been set to something other than "".
I managed to get it sorted in slightly different way using two IF statements
%%[IF #Add3 == "Y" AND #Add4 == "Y" AND #Add5 == "N" THEN
SET #WhichNom1 = "1"
SET #WhichNom2 = "2"
SET #Status = "T"
ELSEIF #Add3 == "Y" AND #Add4 == "N" AND #Add5 == "Y" THEN
SET #WhichNom1 = "1"
SET #WhichNom2 = "3"
SET #Status = "T"
ELSEIF #Add3 == "N" AND #Add4 == "Y" AND #Add5 == "Y" THEN
SET #WhichNom1 = "2"
SET #WhichNom2 = "3"
SET #Status = "T"
ELSE
SET #Status = "F"
ENDIF]%%
%%[IF #Status == "T" THEN]%%
#WhichNom1
#WhichNom2
%%[ENDIF]%%
Rob is correct. Also if you want to print #WhichNom1 and #WhichNom2 outside of the AMPscript block, you'll probably need to code as:
%%[
IF #Add3 == "Y" AND #Add4 == "Y" AND #Add5 == "N" THEN
SET #WhichNom1 = "1"
SET #WhichNom2 = "2"
SET #Status = "T"
ELSEIF #Add3 == "Y" AND #Add4 == "N" AND #Add5 == "Y" THEN
SET #WhichNom1 = "1"
SET #WhichNom2 = "3"
SET #Status = "T"
ELSEIF #Add3 == "N" AND #Add4 == "Y" AND #Add5 == "Y" THEN
SET #WhichNom1 = "2"
SET #WhichNom2 = "3"
SET #Status = "T"
ELSE
SET #Status = "F"
ENDIF
]%%
%%[ IF #Status == "T" THEN ]%%
%%= v(#WhichNom1) =%%<br />
%%= v(#WhichNom2) =%%
%%[ ENDIF ]%%
I'm trying to understand why ! ( ( true || false ) && false ) is true and not false but I can't seem to figure it out.
true || false == true
true && false == false
!false == true
! ( ( true || false ) && false )
is equal to
! ( ( true ) && false )
which is
! ( false )
which is
true
Try to go through it one-by-one:
! ( ( true || false ) && false )
3 ( ( 1 ) 2 )
1) true || false => true because it is true if at least either of them is true.
2) true && false => false because it is only true if both are true, i.e. if at least either of them is false, it evaluates to false.
3) !(false) => true because '!' means negation, the negation of false is true, and the negation of true is false.
For these kind of Boolean logic issues I always try to break it into steps.
So for this the first condition
( true || false )
This is equal to true as you're saying true OR false
The next condition can now be read as
( true && false )
Which is false
The final bit that makes it true as oppssed to false is the !
The final part can be equated to
!( false )
The ! flips the value so the final statement is true