Page 1 of 1

If statements and comparison values

Posted: Wed Aug 19, 2015 6:45 pm
by Randy7611273

Hello!

I am trying to implement an if statement using comparison values. So far, despite much testing, the console always returns if and never else.

My Test Code:

var oneCount = 1;
var twoCount = 2;

if ("{'oneCount':{'$gt':'twoCount'}}") {
console.log ("IFVAR");
} else {
console.log ("ELSEVAR");
}

if ("{2:{'$gt':1}}") {
console.log ("IFNUM");
} else {
console.log ("ELSENUM");
}

Thanks!
Randy


If statements and comparison values

Posted: Wed Aug 19, 2015 7:55 pm
by Serhii Kulibaba

Hello Randy,

You check strings which are not empty, so you always get "true" values.


If statements and comparison values

Posted: Thu Aug 20, 2015 3:35 am
by Randy7611273

I'm sorry, but I do not understand. Could you please provide an example?


If statements and comparison values

Posted: Fri Aug 21, 2015 6:15 pm
by Serhii Kulibaba

You use code:
preif ("{'oneCount':{'$gt':'twoCount'}}") /pre

here pre"{'oneCount':{'$gt':'twoCount'}}"/pre - it is string, which contains pre{'oneCount':{'$gt':'twoCount'}}/pre

So it is not empty string and this result always = true


If statements and comparison values

Posted: Fri Aug 21, 2015 7:30 pm
by Randy7611273

Hello Sergiy,

Is it possible to provide me with an example that will work?

Thanks!
Randy


If statements and comparison values

Posted: Fri Aug 21, 2015 9:53 pm
by Randy7611273

Alright... I'm making progress, but I'm still having issues.

This works:
if ( var1 var2 )

This does not... and neither do any other variations I've tried:
if ( var1 : { "$gt" : var2 } )

I'm running into problems with syntax when trying to use proper comparison values (ex: $gt instead of ).


If statements and comparison values

Posted: Sat Aug 22, 2015 3:55 am
by Evgene Karachevtsev

Hello Randy,

Unfortunately custom js code is outside the scope of standard Appery.io platform support. You may consider purchasing Advisory Pack to get more in-depth help on this question. Here is more information about it: http://appery.io/services/#Advisory_Pack