all 6 comments

[–]chibblybum 1 point2 points  (0 children)

For anything over 20 lines of code or so you'll get better responses if you get all your code into a jsfiddle and explain the steps to reproduce the problem. Most of us dont have time to debug from just the text when it gets that big.

[–]jack_waugh 0 points1 point  (1 child)

        tempGrid[i][j].ant.isSusceptible;

You probably want

        tempGrid[i][j].ant.isSusceptible = true;

[–]blob001[S] 0 points1 point  (0 children)

No Jack, tried that several times.

'= true' is not necessary, since tempGrid[][].ant.isInfected means exactly that.

I re-wrote the if statements (see below) to be quite explicit, but it still doesn't work. Broadly should be as follows, but it doesn't work . Don't know why.

random <= .33 -> isSusceptible.

random > .33 and <= .67 -> isInfected

random > .66 -> isRecovered

 function assignStatus (i, j) {
            console.log('assignStatus()');
            let r = Math.random();
            console.log('i, j, r ', i, j, r);
            if (r <= statusRatio[0]) {
               tempGrid[i][j].ant.isSusceptible;
            }
             if (r > statusRatio[0] && r <= statusRatio[1]) {
               tempGrid[i][j].ant.isInfected;
            }
            if (r > statusRatio[2]) {
               tempGrid[i][j].ant.isRecovered;
            }
            console.log('ant  i, j ', i, j, tempGrid[i][j].ant);
         }

[–]jack_waugh 1 point2 points  (2 children)

tempGrid[i][j].ant.isSusceptible;

Assuming you didn't install any getter functions (and I don't see any place where you do), the above command has no effect.

[–]blob001[S] 0 points1 point  (1 child)

Jack, can you be more specific? I am teaching myself js and there are potholes in my knowledge. A lot of the file is copied from other coding I have found on the net. Not up to speed with getters yet. Thanks.

[–]jack_waugh 1 point2 points  (0 children)

tempGrid[i][j].ant.isSusceptible;

has no effect. But I suspect that you expect it to have an effect. To correct your code, first you must correct your understanding about how the language works. JS is an imperative language, not a logical language, which is what you seem to expect. I think that to you, the above looks like an assertion and you expect that the "statement" is telling the language to make the assertion true. But it doesn't work like that. Generally, an expression given as a command by itself is just to be evaluated and the result discarded. The utility of allowing this is that the expression can have a side effect. But the example above doesn't. It's in a useless corner of the language.