Kunskapsbasen
  • Fullstack Webbutvecklare
  • Material
    • Föreläsningar
    • Uppgifter
      • Ordinarie uppgifter
        • u00-teorihandboken
        • u01-static-website
        • u02-redesign-myh
        • u03-hangman
        • u04-todo-app
        • u05-imdb-clone
        • u06-trello-clone
        • u07-recipe-app
        • u08-recipe-api
        • u09-weather-app
        • u10-business-idea
        • u11-fullstack-js
          • Teknisk kravspecifikation för u11
      • Kompletteringsuppgifter
        • k01-basic-html-css-js
        • k02-php-oop-jquery
          • Teknisk kravspecifikation för k02
        • k03-restful-api-react
          • Teknisk kravspecifikation för k03
      • Övriga uppgifter
        • battleship
        • api-mashup
  • Kurser
  • Alla kurser
    • HTML & CSS, 30yhp
    • UX och design, 30yhp
    • Projektmetodik, 10yhp
    • Programmeringsmetodik, 20yhp
    • JavaScript, 60yhp
    • Backendutveckling, 50yhp
    • Avancerad JavaScript, 40yhp
    • LIA, 120yhp
    • Examensarbete, 40yhp
Powered by GitBook
On this page
  • 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.
  • 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

Was this helpful?

  1. Material
  2. Uppgifter
  3. Övriga uppgifter

battleship

PreviousÖvriga uppgifterNextapi-mashup

Last updated 5 years ago

Was this helpful?

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

Learn about the game and what the rules are here: )

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

https://en.wikipedia.org/wiki/Battleship_(game
document.getElementById()
document.createElement()
appendChild()
Style property in JS
How to loop in JavaScript
Event handling in JavaScript
If-statments in JavaScript