CS2 JavaScript Project
2024 🎰
<<< Back to
main site
Due Date: Thursday, November 7, 2024
Need help? Remember to check out Edstem and our Website for TA help
assistance.
Background 🎰
Be sure to read all background notes, as they are vital to do the assignment.
Assignment Goals
- Showcase understanding of functions, variables, and callbacks
- Add JavaScript event handlers
- Debug using
console.log
Resources
Reminder: This project must be completed by yourself, without the
help of any other students or resources not mentioned in the resource section.
Project Description
🎰
Oh no! Don's Casino is packed with customers and the dealers are overwhelmed. We need your help to
deliver the poker chips to the playing tables. Your task is to use what you've learned in the Javascript
lab to navigate around the maze-like casino floor.
- There are instructions in the stencil file provided. Please read them carefully. We have created
some functions for you to fill in, while others you must write on your own.
- Your project will be graded in Chrome.
- This project requires you to use function calls that are specific to this assignment. Before
starting, read the section titled “Documentation” within "Tasks 🎰".
Tasks 🎰
Setup
Task 0: Double click your "CS2" folder on your desktop, and create
(or enter) your folder for JavaScript
. Then, create a new folder inside
called JavaScript Project
. All your files for the project should live in
this folder.
Task 1: Begin by downloading the stencil here.
This project consists of four files:
index.html
donsCasino.js
donsCasino.css
stencil.js
Put all downloaded files into your JavaScript folder. This is the
folder you will zip at the end of the assignment to turn in on Canvas.
To view what the casino looks like, simply open your index.html
file in
Chrome.
IMPORTANT NOTE: The required tasks do NOT require you to alter any
files other than the stencil.js
file. The only code you write should be in
stencil.js
.
Documentation
We have provided some code for you to use in the project. This code is located in
donsCasino.js
. It's okay if you don't completely understand
what is happening in the functions in this file!! We have provided general
descriptions of these functions below. You can call these functions on the variables to make them do
things in stencil.js
.
Poker Chip Functions
🎰
drawChip(x,y)
- draws the poker chip on-screen at location column x and row y.
changeColor(color)
- changes the color of the poker chip to whatever the value of
color is.
moveLeft()
- makes the poker chip move one unit left
moveRight()
- makes the poker chip move one unit right
moveDown()
- makes the poker chip move one unit down
moveUp()
- makes the poker chip move one unit up
These all must be called on the pokerChip object.
Casino Functions
🎰
changeCasinoBackground(color)
- this function changes the color of the casino to
whatever the value of color
is
This must be called on the casino object.
General Functions
🎰
getRandomColor()
- this function returns a random color
How To Call
Functions
There are two ways these functions can be called
- Functions for specific objects (eg. poker chip or casino) are called as
follows:
Example: To make the poker chip move left we would call its
moveleft
function using this syntax:
And to call the casino’s changeCasinoBackground(color)
we would use the
syntax:
casino.changeCasinoBackground("red");
- General functions are called normally:
Example: To get a random color, we would use the syntax:
You will be writing code in stencil.js
. You do NOT
need to modify anything in donsCasino.js
. These
functions are meant to be called within stencil.js.
Making Poker Chips
To complete an order successfully, you first need to prepare the poker chips.
Task 2: Drawing the Poker Chip
Open stencil.js
. Begin by drawing red poker chips at location
x=1
, y=1
. “Drawing” the poker chips is equivalent to
placing a red square on the maze. Once you have completed this task, you should see a red square in
the top left corner of the casino maze.
Uh oh! Sometimes you mess up the order or the dealer changes their mind about what value chip they
want. When that happens you need to start all over again!
Task 3: Restarting an Order
Fill in the restart()
function in stencil.js
.
To add the restart button functionality, you will need to write code in the function that
reloads the whole page when the maze is restarted.
Remember to add an event listener for the restart button! This should be done at the bottom of the
stencil file in the event handlers section. Think back to the Document Object
Model that we learned in lab. What is the ID for the restart button in the
HTML file?
Hint
You should look into reload for more information on how to do
this.
Navigating the
Maze
Your poker chip must get from one end of the casino floor to the other in order to successfully deliver
it to the dealer.
Task 4: Delivering Poker Chips to a Dealer
Add the ability to control the poker chips with the arrow keys by filling in the
keyDown
function and adding an event listener. This has two main
components:
- The chips should be able to move with the 4 arrow keys in their respective directions. This
will consist of 4 conditionals, 1 for each key event. You can use this website to find out which key maps to
which keyCode value. To check a keycode value (in an if statement, for example), you’d write
something like this:
if (keyCode === 38) {
chip.moveUp();
}
-
You will also have to add an event listener to the window corresponding to the function
you just wrote. See this link for
examples of how to use the keydown
listener in JavaScript.
Here’s an example of adding a listener to the window that listens to the function
doSomething
when keys are pressed:
window.addEventListener('keydown', doSomething);
Task 5a: Changing the Casino Background
When the "New Casino" button is clicked, the casino background should be changed to a random
color.
Recall that we have provided both a changeCasinoBackground()
and a
getRandomColor()
function.
Hint
Remember to add an event listener for the button, as you did above with the restart
button!
Do not create your own random color function; use our existing random color function (see
Documentation)
Task 5b: Changing the Poker Chip values:
When the "New Poker Chip" button is clicked, the chips should be changed to a random color. This
should look very similar to the function in Task 5a!
Debugging Advice
- Make sure to read through the Documentation section and instructions carefully
- Feel free to add a
console.log(“whatever message you want”);
lines in
your functions to help you debug. Right-click on the page, hit Inspect, and go to Console to see the
logs. Error messages will be printed if there are errors. If you want help debugging, this is
definitely an important tool and we are happy to help you with this in hours!
Completing the
Order
Once your poker chip has reached the dealer, you should make sure they are happy with the order.
Task 6: Delivering Your Order
Try solving your maze! Once your poker chip square reaches the end of the maze, a popup should
appear that reads “Congrats! You succesfully delivered the chips!” This is
already implemented for you.
3 points: Add an extra button with JavaScript functionality of your
choice.
This would require you to change the index.html
file to add a button and
id. Your chosen functionality must be sufficiently different from the project requirements (e.g. a
button to make the background blue wouldn't count), and it MUST use some sort of Javascript. It
cannot just link to a website (this can be done in HTML). Some ideas are:
- Add an image and make it appear/disappear
- Add a media file, like audio and video, and control it with a button
- Add text and make it appear/disappear
2 Points: Add a score tracker. This would require you to add an
element to the index.html
file that displays the number of steps your chip
has taken in the format “Score: x” where x is the number of key strokes made to solve the maze. You
would need a score counter variable in your Javascript file that increments every time you move your
poker chip.
Hand-In 🎰
To Hand-In Project 4:
For this assignment, your submission should include the JavaScript file
stencil.js
with the completed functions. Be sure to also include the original
HTML file and the original CSS and JS files with no
changes (unless you made edits for extra credit).
Your files should look like this at submission:
JavaScript Project
├── donsCasino.css
├── donsCasino.js
├── index.html
├── stencil.js
-
Make sure your source files do not contain your
name. This is especially important in order to maintain the
course’s anonymous grading policy that ensures your assignments are graded fairly. We will
deduct points if your files contain identification data.
-
Make sure you have the correct, most up-to-date
files before zipping. We’ve had students in the past send in older
versions that didn’t contain all their finished work! You will receive a 10pt deduction if
TAs must regrade your work due to incorrect files.
-
Create a .zip file from your JavaScript Project
folder.
Windows:
In Windows Explorer, go to the folder containing the files you want to zip. Select the
files, then right-click on any of the selected files and select Send To… ->
Compressed (zipped) Folder.
Mac:
In Mac Finder, go to the folder containing the files you want to zip. (This would be
your “JavaScript Project” folder) Select the files, then right-click on any of the
selected files and select Compress Items.
-
Right click on the newly created zip file to rename it. The name of your file should be
BannerID_JavaScriptProject.zip
(replace "BannerID" with your own
banner id, starting with B0...
)
-
Submit on Canvas under the JavaScript Project assignment!
Congrats! You just finished the Javascript Project!
CS2 JavaScript Project 2024 🎰
<<< Back to main site
Background 🎰
Assignment Goals
console.log
Resources
Reminder: This project must be completed by yourself, without the help of any other students or resources not mentioned in the resource section.
Project Description 🎰
Oh no! Don's Casino is packed with customers and the dealers are overwhelmed. We need your help to deliver the poker chips to the playing tables. Your task is to use what you've learned in the Javascript lab to navigate around the maze-like casino floor.
Tasks 🎰
Setup
Task 0: Double click your "CS2" folder on your desktop, and create (or enter) your folder for
JavaScript
. Then, create a new folder inside calledJavaScript Project
. All your files for the project should live in this folder.Task 1: Begin by downloading the stencil here.
This project consists of four files:
index.html
donsCasino.js
donsCasino.css
stencil.js
Put all downloaded files into your JavaScript folder. This is the folder you will zip at the end of the assignment to turn in on Canvas.
To view what the casino looks like, simply open your
index.html
file in Chrome.IMPORTANT NOTE: The required tasks do NOT require you to alter any files other than the
stencil.js
file. The only code you write should be instencil.js
.Documentation
We have provided some code for you to use in the project. This code is located in
donsCasino.js
. It's okay if you don't completely understand what is happening in the functions in this file!! We have provided general descriptions of these functions below. You can call these functions on the variables to make them do things instencil.js
.Poker Chip Functions 🎰
drawChip(x,y)
- draws the poker chip on-screen at location column x and row y.changeColor(color)
- changes the color of the poker chip to whatever the value of color is.moveLeft()
- makes the poker chip move one unit leftmoveRight()
- makes the poker chip move one unit rightmoveDown()
- makes the poker chip move one unit downmoveUp()
- makes the poker chip move one unit upCasino Functions 🎰
changeCasinoBackground(color)
- this function changes the color of the casino to whatever the value ofcolor
isGeneral Functions 🎰
getRandomColor()
- this function returns a random colorHow To Call Functions
There are two ways these functions can be called
Example: To make the poker chip move left we would call its
moveleft
function using this syntax:And to call the casino’s
changeCasinoBackground(color)
we would use the syntax:Example: To get a random color, we would use the syntax:
You will be writing code in
stencil.js
. You do NOT need to modify anything indonsCasino.js
. These functions are meant to be called within stencil.js.Making Poker Chips
To complete an order successfully, you first need to prepare the poker chips.
Task 2: Drawing the Poker Chip
Open
stencil.js
. Begin by drawing red poker chips at locationx=1
,y=1
. “Drawing” the poker chips is equivalent to placing a red square on the maze. Once you have completed this task, you should see a red square in the top left corner of the casino maze.Uh oh! Sometimes you mess up the order or the dealer changes their mind about what value chip they want. When that happens you need to start all over again!
Task 3: Restarting an Order
Fill in the
restart()
function instencil.js
. To add the restart button functionality, you will need to write code in the function that reloads the whole page when the maze is restarted.Remember to add an event listener for the restart button! This should be done at the bottom of the stencil file in the event handlers section. Think back to the Document Object Model that we learned in lab. What is the ID for the restart button in the HTML file?
Hint
You should look into reload for more information on how to do this.
Navigating the Maze
Your poker chip must get from one end of the casino floor to the other in order to successfully deliver it to the dealer.
Task 4: Delivering Poker Chips to a Dealer
Add the ability to control the poker chips with the arrow keys by filling in the
keyDown
function and adding an event listener. This has two main components:You will also have to add an event listener to the window corresponding to the function you just wrote. See this link for examples of how to use the
keydown
listener in JavaScript.Here’s an example of adding a listener to the window that listens to the function
doSomething
when keys are pressed:Buttons
Task 5a: Changing the Casino Background
When the "New Casino" button is clicked, the casino background should be changed to a random color.
Recall that we have provided both a
changeCasinoBackground()
and agetRandomColor()
function.Hint
Remember to add an event listener for the button, as you did above with the restart button!
Do not create your own random color function; use our existing random color function (see Documentation)
Task 5b: Changing the Poker Chip values:
When the "New Poker Chip" button is clicked, the chips should be changed to a random color. This should look very similar to the function in Task 5a!
Debugging Advice
console.log(“whatever message you want”);
lines in your functions to help you debug. Right-click on the page, hit Inspect, and go to Console to see the logs. Error messages will be printed if there are errors. If you want help debugging, this is definitely an important tool and we are happy to help you with this in hours!Completing the Order
Once your poker chip has reached the dealer, you should make sure they are happy with the order.
Task 6: Delivering Your Order
Try solving your maze! Once your poker chip square reaches the end of the maze, a popup should appear that reads “Congrats! You succesfully delivered the chips!” This is already implemented for you.
Extra Credit 🎰
3 points: Add an extra button with JavaScript functionality of your choice.
This would require you to change the
index.html
file to add a button and id. Your chosen functionality must be sufficiently different from the project requirements (e.g. a button to make the background blue wouldn't count), and it MUST use some sort of Javascript. It cannot just link to a website (this can be done in HTML). Some ideas are:2 Points: Add a score tracker. This would require you to add an element to the
index.html
file that displays the number of steps your chip has taken in the format “Score: x” where x is the number of key strokes made to solve the maze. You would need a score counter variable in your Javascript file that increments every time you move your poker chip.Hand-In 🎰
To Hand-In Project 4:
For this assignment, your submission should include the JavaScript file
stencil.js
with the completed functions. Be sure to also include the original HTML file and the original CSS and JS files with no changes (unless you made edits for extra credit).Your files should look like this at submission:
Make sure your source files do not contain your name. This is especially important in order to maintain the course’s anonymous grading policy that ensures your assignments are graded fairly. We will deduct points if your files contain identification data.
Make sure you have the correct, most up-to-date files before zipping. We’ve had students in the past send in older versions that didn’t contain all their finished work! You will receive a 10pt deduction if TAs must regrade your work due to incorrect files.
Create a .zip file from your
JavaScript Project
folder.Windows:
In Windows Explorer, go to the folder containing the files you want to zip. Select the files, then right-click on any of the selected files and select Send To… -> Compressed (zipped) Folder.
Mac:
In Mac Finder, go to the folder containing the files you want to zip. (This would be your “JavaScript Project” folder) Select the files, then right-click on any of the selected files and select Compress Items.
Right click on the newly created zip file to rename it. The name of your file should be
BannerID_JavaScriptProject.zip
(replace "BannerID" with your own banner id, starting withB0...
)Submit on Canvas under the JavaScript Project assignment!
Congrats! You just finished the Javascript Project!
If you have any issues with completing this assignment, please reach out the course HTAs: cs0020headtas@lists.brown.edu
If you need to request an extension, contact Professor Stanford directly: don.stanford@gmail.com