battleship

The assignment is to re-create the popular board game battleship game using JavaScript.

Learn about the game and what the rules are here: https://en.wikipedia.org/wiki/Battleship_(game)

All the code the functions that are needed are outlined in the JS-file. No need to add more unless you want to. Read the comments in the code carefully.

Step 1: Get started by reading through the battleship.js file. All that you need to solve the assignment is described in comments

Step 2: Use the for-loops defined in the code to generate a grid.

References for the methods in JS that are needed for this step:

Step 3: Attach event-listeners to each square in the grid and trigger the guess() function on click

Step 4: Add the logic that's needed for the game to be playable

Step 5: Play! Make sure you can win

A player should be able to sink all the ships, look in the js-file for the ship positions to make this easier to test.

BONUS tasks (optional):

  • Add graphics, animation

  • Add support for randomizing the grid

  • Add support for resetting the game without having to reload the webpage

  • Add support for multiplayer

Last updated