Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

If statements and comparison values

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

If statements and comparison values

Hello Randy,

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

Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

If statements and comparison values

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

If statements and comparison values

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

Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

If statements and comparison values

Hello Sergiy,

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

Thanks!
Randy

Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

If statements and comparison values

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 ).

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

If statements and comparison values

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

Return to “Issues”