Battleships Move Codehs Free — 3.3.6
function drawGrid() // Already implemented: draws the grid and ship
A: You likely forgot that drawGrid() is called automatically by the CodeHS runner. Make sure your moveShip only updates shipRow and shipCol . Do not call drawGrid yourself unless the skeleton explicitly asks for it. 3.3.6 battleships move codehs
. The program doesn't "see" a ship; it sees a coordinate in a 2D array (a grid). When a player enters a row and a column, the code must translate those numbers into a specific index to check the status of that cell. Validation: The First Line of Defense A critical part of the move logic is input validation function drawGrid() // Already implemented: draws the grid
To solve 3.3.6, you must think like an architect. You aren't just writing one long script; you are designing a system. The CodeHS environment usually provides a setup where you work with a Grid object and a Ship object. Validation: The First Line of Defense A critical
To complete the 3.3.6 exercise, you must add an if-else statement to the move method where position += 7 occurs when safeToMove is true, and position -= 2 occurs when it is false.