Zahra Naqvi
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # CS2 JavaScript Project 2024 🎰 [<<< Back to main site](https://cs.brown.edu/courses/csci0020/) <img src="https://hackmd.io/_uploads/H1NagEAT3.png" width=200> > **Due Date: 11/09/2023** > **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 - **CS2 Javascript Lab**: functions, variables, and callbacks, DOM, simple JavaScript events - [Official Javascript Documentation](https://devdocs.io/javascript/) - [Javascript Documentation at W3Schools](https://www.w3schools.com/js/js_functions.asp) - TA hours and EdStem! :::warning **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 TAs 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 pit. - 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 :::info **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. ::: :::info **Task 1**: Begin by downloading the stencil [`here`](https://drive.google.com/drive/folders/18UeVgn2OC_4qbz_qiI0WaUCdp6CXJEVX?usp=drive_link). **This project consists of four files:** 1. `index.html` 2. `donsCasino.js` 3. `donsCasino.css` 4. `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. ::: :::warning **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 1. ==Functions for specific objects (eg. poker chip or casino) are called as follows:== ```javascript= object.function(param); ``` **Example**: To make the poker chip move left we would call its ```moveleft``` function using this syntax: ```javascript= chip.moveleft(); ``` And to call the casino’s ```changeCasinoBackground(color)``` we would use the syntax: ```javascript= casino.changeCasinoBackground("red"); ``` 2. ==General functions are called normally==: ```javascript= function(param); ``` **Example**: To get a random color, we would use the syntax: ```javascript= getRandomColor(); ``` :::warning You will be writing code in `stencil.js`. **You do NOT need to modify anything in `donsCreamery.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. :::info **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 parlor maze. ::: Uh oh! Sometimes you mess up the order or the customer changes their mind about what value chip they want. When that happens you need to start all over again! :::info **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? :::spoiler **Hint** You should look into [reload](https://www.w3schools.com/jsref/met_loc_reload.asp) for more information on how to do this. ::: ### Navigating the Maze Your poker chip must get from one end of the parlor to the other in order to successfully deliver it to the customer. :::info **Task 4: Delivering Poker Chips to a Customer** 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: 1. 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`](https://keycode.info) 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: ```javascript= if (keyCode === 38) { chip.moveUp(); } ``` 2. You will also have to add an event listener to the [`window`](https://www.w3schools.com/js/js_window.asp) corresponding to the function you just wrote. See [`this link`](https://www.geeksforgeeks.org/javascript-detecting-the-pressed-arrow-key/) 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: ``` javascript= window.addEventListener('keydown', doSomething); ``` ::: ### Buttons :::info **Task 5a: Changing the Parlor Background** When the "New Parlor" button is clicked, the parlor background should be changed to a random color. Recall that we have provided both a `changeCasinoBackground()` and a `generateRandomColor()` function. :::spoiler **Hint** Remember to add an event listener for the button, as you did above with the restart button! ::: :::warning Do not create your own random color function; use our existing random color function (see Documentation) ::: :::info **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 customer, you should make sure they are happy with the order. :::info **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 🎰 :::info **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 ::: :::info **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 ice cream. ::: :::info **2 Points**: Fill out our [feedback form](https://docs.google.com/forms/d/e/1FAIpQLScdLX2aY7uG_PH8Ei39NKdk81op22e6Qy06fU-PIWWMSmONEA/viewform?usp=sf_link). ::: ## Hand-In 🎰 :::success **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 ``` 1. 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. 2. 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 10% deduction if TAs must regrade your work due to incorrect files. 3. Create a .zip file from your `JavaScript Project` folder. :::spoiler 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. ::: :::spoiler 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. ::: 4. 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...`) 5. Submit on Canvas under the JavaScript Project assignment! Congrats! You just finished the Javascript Project! :slot_machine: ::: :::warning 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 :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully