tayasignal.blogg.se

Eloquent javascript chess board
Eloquent javascript chess board






So instead of A,1 like on a chessboard, the formula will call it 0,0, or A,5 on the chessboard would be 0,4, or D,6 would be 3,5. Take this image of a chessboard for example, you have the number row and the letter columns īut because you can't really use letters, were using numbers. So j will run 8 times, for a total of 8 times within i. Remember, each loop is bound to its limit, which is 8. Using i + j is to help keep all the squares and rows separate, unique and alternating. The reason your method was wrong, is because you're kinda cheating the function you wrote isn't working like a "chessboard", if you catch my drift? You're just printing predefined rows instead of building it square by square (systematically), if this makes sense? I've added a console log line that will show you what i and j equal each time the for loop runs. To help visualise what's happening, run this let size = 8 I only ever increments when j's loop has finished, alas why a new line is created when j's loop finishes and triggers i to start the next line. The next time it runs, i=0, j=1 therefore (0+1) % 2 = 0 is false and our second square in the first row will be a hash. So the first square in our first row will be blank. The for loop and nested for loop runs as follows When I read the book solution's logic, I would think the output would show: I would have thought just have just i or j % 2=0 would make sense, the i + j confuses me here. I do not understand why the 'if' logic in the nested loop has (i + j) % 2 = 0.

eloquent javascript chess board

I understand this is inefficient, but I was confused by the logic in the book's solution's code. I have a question about the chessboard problem that asks you to output this: Over the last month, I've been taking Harvard's CS50 course (learning C) and recently bought Eloquent Javascript, as I'm looking to get into Web development. Personal blog posts that are relevant to the subreddit's stated subject matter don't need prior approval (and are encouraged!).

#ELOQUENT JAVASCRIPT CHESS BOARD MODS#

If you want to post something self-promotional, please message the mods first. Titles that begin with "hey guys" will be removed. If you're in doubt, message the mods first.

eloquent javascript chess board

The following are not allowed: Requests for subscribers, asking for "test users" for your new JS course, offering paid mentorships, and/or premium courses. If you’re asking for help, include enough information for others to recreate your problem. With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged. Everyone should feel comfortable asking any and all JavaScript questions they have here. This subreddit is a place for people to learn JavaScript together.






Eloquent javascript chess board