-1

I'm trying to compare to functions. Each function have this: return returnArr.toString(); as a return, which are strings both of them.

if ( moveRight() == paintFood(235,10,"blue") ){
alert("Food!")
};

But it's not the same like this one:

if ("A" == "A"){
alert("Right comparison");
};

Why ???

leppie
  • 115,091
  • 17
  • 196
  • 297
Denis Doan
  • 73
  • 1
  • 8

2 Answers2

0
new String("a") == new String("a")

evaluates to false.

Try

if ( moveRight().valueOf() == paintFood(235,10,"blue").valueOf() ){

instead.

eTomate
  • 231
  • 1
  • 11
0

Thanks for your help. Problem solved meanwhile. The if condition is put within a function to runs it whether it is needed, which the if condition only was not at the right place:

function check (){
if ( moveRight() == paintFood(235,10,"blue") ){
alert("Food!")
};
};
Denis Doan
  • 73
  • 1
  • 8