You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The logic going on in this game is intense and I love how far it's come
Ternaries are beautiful, but they're not the right tool for everything:
<divkey={colIndex}className={`cell ${// this evaluation is overly complicated and feels uncertaincell==='B'||cell==='A' ? 'ship-cell' : ''}`}>
Short-circuit Evaluations are also friends!!
<divkey={colIndex}className={`cell ${// this evaluation is simple and clear// you can evaluate `cell` as a boolean because it initializes as `null`cell&&'ship-cell'}`}>
Watch out for your file structure / organisation:
![[Screenshot 2023-10-18 at 15.37.17.png]]
Two Game.jsx files, tsk tsk...
Your logic on placeShip.jsx is honestly impressive. I was also partial to your clean up by packaging some logic into helper functions for readability. One other suggestion I would make is maybe bundling props into objects just for the sake of removing noise from the screen:
constnewShip={row: Math.floor(Math.random()*numRows),// did you notice these two col: Math.floor(Math.random()*numCols),// could just be numCells ??orientation: Math.floor(Math.random()*2)}if(canPlaceShip(newShip,actionProps)){// here I've also packaged the rest of the props that were drilled in from Game.jsxfor(leti=0;i<shipLength;i++){newShip.orientation===0 ? // this was a ternary waiting to happenboard[newShip.row][newShip.col+i]='B' :
board[newShip.row+i][newShip.col]='A';}
On another note, that file did not need to be a .jsx since it doesn't return a component.
The text was updated successfully, but these errors were encountered:
Short-circuit Evaluations are also friends!!
![[Screenshot 2023-10-18 at 15.37.17.png]]
Two
Game.jsx
files, tsk tsk...placeShip.jsx
is honestly impressive. I was also partial to your clean up by packaging some logic into helper functions for readability. One other suggestion I would make is maybe bundling props into objects just for the sake of removing noise from the screen:.jsx
since it doesn't return a component.The text was updated successfully, but these errors were encountered: