COMP519 Web Programming (2017-18) -- Assignment 2: JavaScript

Your task for this practical assignment consists of two parts:

  1. Develop a JavaScript program that provides the functionality stated in the Requirements section below.
  2. Make the system that you have created accessible and usable via the URL<your user name>/game.html
    taking care that the access rights for the file and all other files related to your solution are neither too restrictive nor too permissive.


The program simulates a simple game of chance using three to six dice. The dice are six-sided and each side has a distinct number between 1 and 6 on it. When a dice is rolled, then each number occurs with equal chance. The game proceeds in three stages, setup, play, and end stage.

During the setup stage the user is asked to enter the number of dice that will be used in the game. If the input of the user is not a natural number between 3 and 6, then an error message should be shown and the user is asked again for a number. This continues until the input of the user is a natural number between 3 and 6, denoted by N in the following. The check and error messages must be realised using JavaScript, not using HTML5 elements and attributes.

During the play stage the game proceeds in rounds during which the program maintains a balance of points won and the number of rounds played. Initialy, both balance and number of rounds played is zero.

In each round, the program first increments the number of rounds played by one, then rolls the N dice and computes the number of points won according to the following table:
Description Points Calculation Example
(with four dice)
Example Points Calculation
All N dice have the same value 60 + Sum of the values of all the dice 3,3,3,3 60 + 3 + 3 + 3 + 3 = 72
N - 1 but not N dice have the same value 40 + Sum of the values of all the dice 4,4,4,6 40 + 4 + 4 + 4 + 6 = 58
2,5,2,2 40 + 2 + 5 + 2 + 2 = 51
A run
(a sequence K+1 to K+N for some K ≥ 0)
20 + Sum of the values of all the dice 3,4,5,6 20 + 3 + 4 + 5 + 6 = 38
4,3,2,1 20 + 4 + 3 + 2 + 1 = 30
4,6,3,5 20 + 4 + 6 + 3 + 5 = 38
All dice have different values, but it is not a run Sum of the values of all the dice 4,5,3,1 4 + 5 + 3 + 1 = 13
3,6,2,5 3 + 6 + 2 + 5 = 16
Any other outcome 0 4,5,3,3 0

The number of points won is then added to the balance of points and constitutes the balance at the end of the round.

The program will then display

  • the number of rounds played,
  • the dice values (possibly in the form of a nice graphical representation),
  • the number points won in that round, and
  • the balance of points at the end of the round.

The program then provides the user with the options (i) to continue with another round, or (ii) to end the game. If option (i) is chosen, then the program remains in the play stage and proceeds with another round. If option (ii) is chosen, then the program proceeds to the end stage.

In the end stage, the program computes the average number of points won per round and displays

  • the number of rounds played,
  • the balance of points when reaching the end stage,
  • the average number of points won per round played.
Additional requirements and comments:

  • The bulk of your JavaScript code should be in a JavaScript library called game.js. Before submitting your solution, you should create a copy of game.js named game.pretty.js in a directory other than your public_html directory, say, your home directory. Then make the file game.js indecipherable for humans using the command uglifyjs $HOME/game.pretty.js --compress --mangle > $HOME/public_html/game.js. Make sure that after performing this operation your game still works.
  • Use of images for the dice and absence of JavaScript prompts and alerts improve the quality of the game design. Remember that if you use images, then they must be your own or your use must be legal under copyright law. You should also provide a reference for the source or sources of your images in your code.
  • Within each round of the play stage, the user only needs to be shown the information for the current round, there is no requirement that the user can still see what happened in previous rounds. Indeed, it may result in better quality game design if they do not.
  • JavaScript engines differ from browser to browser. You should make sure that your system works in all commonly used browsers (e.g., Google Chrome, Mozilla Firefox, Microsoft Internet Explorer 9 or higher) and on all commonly used platforms (e.g., Linux derivatives and Microsoft Windows).
  • Your JavaScript program should only depend on your own code. JavaScript libraries/frameworks should not be used.
  • Your code should follow the COMP519 Coding Standard. This includes pointing out which parts of your code have been developed with the help of on-line sources or textbooks and references for these sources.


Submit all relevant files (game.html, game.js, game.pretty.js, any CSS file, and local images) via the departmental submission system at (COMP519-2: Assignment2N (JavaScript)). Do not forget to also make game.html, game.js, and other files (but not game.pretty.js) accessible via the departmental web server.


The deadline for this practical assignment is

Friday, 10 November 2017, 17:00

Earlier submission is possible, but any submission after the deadline attracts the standard lateness penalties. Please remember that a strict interpretation of `lateness' is applied by the Department, that is, a submission on Friday, 10 November 2017, 17:01 is considered to be a day late.


This practical assignment will address the following learning outcomes of the module:

  • be able to demonstrate an understanding of the range of technologies and programming languages available to organisations and businesses and be able to choose an appropriate architecture for a web application.
  • be able to make informed and critical decisions, design and implement reasonably sophisticated client-side web applications using HTML and JavaScript.

This practical assignment will contribute 25% to the overall mark of COMP519. Failure on this assignment may be compensated by higher marks on other assignments for this module.

Marks will be awarded according to the following scheme:

  • The JavaScript program is accessible via the required URL, works without producing script errors, all required files were submitted, the files accessible via the web are identical to those that were submitted, and the access rights of the files in your filestore must be such that no other user can view their contents in the filestore: 8
  • Quality of the interface design and works with all browsers that were tested: 15
  • Correctness and quality of the implementation of the setup stage: 9
  • Correctness and quality of the implementation of the play stage: 44
  • Correctness and quality of the implementation of the end stage: 4
  • Use of suitable functions and data structures for the computations: 8
  • Formatting, commenting, and quality of code: 12

As stated above, the University policy on late submissions applies to this assignment as does the University policy on Academic Integrity, which can be found at You should follow the COMP519 Lab Rules to ensure that you do not breach that policy.