noc-book-2 icon indicating copy to clipboard operation
noc-book-2 copied to clipboard

Fix step() method for Walker class in Introduction

Open mattholamieux opened this issue 3 years ago • 1 comments

In line 224 of the Introduction, void should be removed from the front of the method declaration.

Additionally, the if/else block starting on line 239 is missing this. for each of the changes to x and y.

The full method should read

    step() {
      let choice = floor(random(4));

      if (choice == 0) {
        this.x++;
      } else if (choice == 1) {
        this.x--;
      } else if (choice == 2) {
        this.y++;
      } else {
        this.y--;
      }
    }

Finally, as a reader, I personally find it confusing to have the explanation on lines 228-235 inserted in the middle of the two halves of this method declaration.

mattholamieux avatar Feb 17 '22 03:02 mattholamieux

The code has been updated, leaving this issue open to consider adjusting the flow of the code. I like to break up long code blocks as they can a lot on the page but I do see your point about this one being confusing!

shiffman avatar Oct 28 '22 19:10 shiffman

I rewrote the text to keep this function all together which I agree is less confusing. It'll be in the next website update (later today).

https://nature-of-code-2nd-edition.netlify.app/introduction/

shiffman avatar Feb 11 '23 20:02 shiffman