3.3.6 Battleships Move Codehs -

function moveShip(e) var key = e.key; var newX = ship.getX();

function drawGrid() // Already implemented: draws the grid and ship 3.3.6 battleships move codehs

Have a different version of the exercise or need help with a specific error? Leave a comment below or consult the CodeHS discussion forum for this module. function moveShip(e) var key = e

Initialize two ships, such as a "Submarine" and a "Carrier". Print their initial positions. Call submarine.move(true) and carrier.move(false) . Print their initial positions

Here’s a content guide to help you understand and complete the exercise on CodeHS.

To verify your code works, you must use the BattleshipTester class (often provided in the exercise). This class creates instances of your Battleship and calls the move method to see if the internal position state updates correctly.

Writing shipRow-- directly inside the if block without temporary variables. Why it fails: If the move is invalid, you have already changed the ship’s position. There is no "undo" mechanism. Fix: Use temporary variables ( newRow , newCol ) and only assign shipRow = newRow after validation.