noc-book-2
noc-book-2 copied to clipboard
Fix step() method for Walker class in Introduction
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.
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!
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/