1

I am putting together a Google Apps script which interfaces with a Google spreadsheet. I am trying to compare two different cells, but they are comparing equal.

Within my for loop, I make make the comparison

    if (cell[n][0] == failureCell)
    {
      failureFlag = 1;
      Logger.log(cell[n][0]);
      Logger.log(failureCell);
    }

I have also tried using the toString() method on each object, but it does not change the return values or the logger values.

The log returns

[15-01-02 18:02:40:312 PST] Value1
[15-01-02 18:02:40:313 PST] FailValue
[15-01-02 18:02:40:524 PST] Value2
[15-01-02 18:02:40:525 PST] FailValue
[15-01-02 18:02:41:235 PST] Value3
[15-01-02 18:02:41:244 PST] FailValue

Here is a screencap of the area of interest in my spreadsheet:

enter image description here

  • What happens if you use 3 equal signs? `if (cell[n][0] === failureCell)` – Alan Wells Jan 03 '15 at 02:37
  • 1
    That fixed the problem. Thanks for your help, I am new to JS. For anyone else who has run into a similar problem, more information on the == vs === operators can be found in this SO question: http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons – stupidgoddamnjerk Jan 03 '15 at 02:42

1 Answers1

0

For the sake of letting people know that this question has been answered, I just wanted to enter something here:

I think you need to use 3 equal signs instead of 2:

You have:

if (cell[n][0] == failureCell)

Should be:

if (cell[n][0] === failureCell)
Alan Wells
  • 30,746
  • 15
  • 104
  • 152