tl3250
    • 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
    # Problem and Product **Problem**: * A consolidated site for people to find great artisan coffee shops around NYC with information including name, image, location, and rating. * Interactive experience that potential users could not only filter by clicking on the dropdown for the cafe's location or the rating but also engage with click-and-expand features of each coffee shop card to see more information/recommendations that are tailored to their interests. * In an ideal world that we have all the technical knowledge, this site could even leverage AI to create personalized recommendations. **Link to CodePen**: https://codepen.io/wt2364/pen/RwvmeKZ # Changes ### 1. Sign In Logic (Tina) **a. Storing Existing User's Data** Utilizing objects and arrays and if else function to prompt alerts when clicking the signin button. **b. Login Prompt** Stored existing user data using our group's information ```javascript! const users = [ { username: "Tina", password: "000" }, { username: "Marsha", password: "111" }, { username: "Wandy", password: "222" } ] ``` **c. Conditions** With ChatGPT's help, we created function that clicking on the sign-in button would result in the prompting of username and password input box. ```javascript! function signIn() { const username = prompt("Enter your username:"); const password = prompt("Enter your password:"); const foundUser = users.find( (user) => user.username === username && user.password === password ); } ``` Use if else function to give alerts according to whether the username and password matches ```javascript! if (foundUser) { alert("Logged in successfully!"); } else { alert("Invalid username or password. Please try again."); } ```` ### 2. Layouting **a. Array to shorten HTML (Marsha)** We recognize the ability of loop function to automate design process. Now we're able to use as minimum space as possible in HTML. ```htmlembedded! <div class="row row-cols-1 row-cols-md-3 g-4 py-5" id="coffeeShopList"> <!-- Location of Template Literal --> </div> ``` ```javascript! // Coffee shops list const coffeeShops = [ { name: "Korbrick Coffee Co.", location: "Chelsea/West Village", address: "24 9th Ave, New York, NY 10014", image: "https://dw82ptradz9jo.cloudfront.net/daylog/6203524894d75733cd3bcbb2/103f254a-3d21-4245-a4ce-3949405fa679", website: "https://www.kobricks.com/", rating: 4.4 }, ... ]; ``` Storing the list as an array made it possible for us to implement DRY principle. Not only did it preserve the styling given the possibility of growing number of the data, but also to utilize some of the elements for other developments. **b. Styling Automation (Wandee)** We use template literal for a modal displaying detailed information about a coffee shop. The modal includes the coffee shop’s name, image, location, address, website, and rating. The modal ID is dynamically set based on the provided index. ```javascript! function generateCoffeeShopHTML(coffeeShop, index) { return ` <div class="col"> <div class="card h-100" data-bs-toggle="modal" data-bs-target="#coffeeShopModal${index}" data-coffee-shop="${JSON.stringify(coffeeShop)}"> <img src="${coffeeShop.image}" class="card-img-top" alt="${coffeeShop.name}"> <div class="card-body"> <h6 class="card-title">${coffeeShop.name}</h6> <p class="card-text">${coffeeShop.location}</p> </div> </div> </div> ``` We iterate over each item in the coffeeShops array. For each coffee shop, generate its HTML representation and append it to the coffeeShopListContainer. ```javascript! coffeeShops.forEach((coffeeShop, index) => { coffeeShopListContainer.innerHTML += generateCoffeeShopHTML( coffeeShop, index ); }); ``` We create a function to generate HTML content for a set of carousel boxes that display random coffee shops as recommendations, excluding the coffee shop currently being viewed. ```javascript! function generateCarouselBoxes(excludedIndex) { let carouselBoxes = ""; const numberOfBoxes = 6; // Define the number of carousel boxes to display. // Set to store indices of coffee shops to ensure unique selection. let selectedIndices = new Set(); // Randomly select unique indices for coffee shops until the set has the // required number of indices. while (selectedIndices.size < numberOfBoxes) { let randomIndex = Math.floor(Math.random() * coffeeShops.length); if (randomIndex !== excludedIndex) { selectedIndices.add(randomIndex); } } ``` For each selected index, generate the HTML for a carousel box and append it to the carouselBoxes string. ```javascript! selectedIndices.forEach((index) => { carouselBoxes += ` <div class="box"> <img src="${coffeeShops[index].image}"> <div> <p class="container1">${coffeeShops[index].name}</p> </div> </div> `; }); ``` ### 3. Dropdown for filter We have two dropdown filters: **📍 location** **⭐️ rating** Both have similar logical sequence to develop: • Generate options • Insert options under the HTML dropdown code • Event listener • Change button text after an option is clicked **a. Location** ```htmlembedded! <div class="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false" id="locationDropdown"> Location </button> <ul class="dropdown-menu" aria-labelledby="locationDropdown"> <!-- Options generated from Javascript --> </ul> </div> ``` * **Generate Options (Marsha)** In this process, we tried to make the most of the array's location element in order to not write the same lines of code more than once. However, we realized it's necessary to provide option for both location and ratings dropdowns to go back to see all options. To achieve that, we put an additional string "See All" above getting all the location values. After populating the options, we asked the function to insert them to the dropdown button in HTML under the correct ID with the template literal. ```javascript! function generateLocationOptions() { const uniqueLocations = [ "See All", ...new Set(coffeeShops.map((shop) => shop.location)) ]; const locationDropdown = document.getElementById("locationDropdown"); const locationDropdownMenu = locationDropdown.nextElementSibling; const locationOptionsHTML = uniqueLocations .map( (location) => `<li><a class="dropdown-item" href="#" data-location="${location}">${location}</a></li>` ) .join(""); locationDropdownMenu.innerHTML = locationOptionsHTML; ``` * **Event listener (Tina)** ```javascript! locationDropdownMenu.addEventListener("click", function (event) { if (event.target.classList.contains("dropdown-item")) { selectedLocation = event.target.innerText; displayCoffeeShops(selectedLocation, selectedRating); updateLocationButtonText(selectedLocation); } }); } ``` * **Change button text after an option is clicked (Tina)** ```javascript! function updateLocationButtonText(location) { const locationButton = document.getElementById("locationDropdown"); locationButton.textContent = location; } ``` **b. Rating (Tina)** ```htmlembedded! <div class="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false" id="ratingDropdown"> Rating </button> <ul class="dropdown-menu" aria-labelledby="ratingDropdown"> <!-- JavaScript will dynamically populate this part --> </ul> </div> ``` * **Generate Options** Make ratings a range. Used if else functions to make ratings a range so that this filter is meaningful for users: ```javascript! function generateRatingOptions() { const ratingRanges = ["See All", "3.5-3.9", "4.0-4.4", "4.5-5.0"]; const ratingDropdown = document.getElementById("ratingDropdown"); const ratingDropdownMenu = ratingDropdown.nextElementSibling; const ratingOptionsHTML = ratingRanges .map( (range) => `<li><a class="dropdown-item" href="#" data-rating-range="${range}">${range}</a></li>` ) .join(""); ratingDropdownMenu.innerHTML = ratingOptionsHTML; ``` * **Event listener** ```javascript! ratingDropdownMenu.addEventListener("click", function (event) { if (event.target.classList.contains("dropdown-item")) { const selectedRatingRange = event.target.dataset.ratingRange; selectedRating = selectedRatingRange; displayCoffeeShops(selectedLocation, selectedRating); updateRatingButtonText(selectedRatingRange); } }); } ``` * **Change button text after an option is clicked** ```javascript! function updateRatingButtonText(rating) { const ratingButton = document.getElementById("ratingDropdown"); ratingButton.textContent = rating; } ``` **c. Filter Function (Marsha)** * **Display coffee shops based on the selected location and rating** ```javascript! function displayCoffeeShops(location, ratingRange) { let filteredCoffeeShops = coffeeShops; ``` * **Filtering based on location** Only if the choosen option is NOT see all then the display will filter the locations. ```javascript! if (location && location !== "See All") { filteredCoffeeShops = filteredCoffeeShops.filter( (shop) => shop.location === location ); } ``` * **Filtering based on rating range** And only if the choosen option is NOT see all then the display will filter the rating range. ```javascript! if (ratingRange && ratingRange !== "See All") { filteredCoffeeShops = filteredCoffeeShops.filter((shop) => { const rating = shop.rating; if (ratingRange === "3.5-3.9") { return rating >= 3.5 && rating <= 3.9; } else if (ratingRange === "4.0-4.4") { return rating >= 4.0 && rating <= 4.4; } else if (ratingRange === "4.5-5.0") { return rating >= 4.5 && rating <= 5.0; } return true; // Return true for any other case or if 'See All' is selected }); } const coffeeShopList = document.getElementById("coffeeShopList"); ``` * **Clear existing content** This is to enable user put options interchangeably. ```javascript! coffeeShopList.innerHTML = ""; ``` * **Display filtered coffee shops** In this process, we noticed that even asking ChatGPT would require our own ability to scrutinize and select snippets of codes to again keep the DRY principle remain applicable. Now that it looks simple and seems like no necessary issue should happened with this loop, the lesson learnt was that try to always call the existing variable instead of writing new lines of codes if we are expecting a same thing to happen for different functions. ```javascript! filteredCoffeeShops.forEach((shop, index) => { coffeeShopList.innerHTML += generateCoffeeShopHTML(shop, index); }); } ``` * **Setting "See All" as neutral position** ```javascript! displayCoffeeShops("See All", "See All"); ``` * **Call the functions to generate location and rating options** ```javascript! generateLocationOptions(); generateRatingOptions(); ``` ### 4. Newsletter (Tina) **a. Store user information into a new object:** Saving information from input field to a new object. ```javascript! function collectAndStoreData() { const fullName = document.querySelector('input[placeholder="Full Name"]') .value; const email = document.querySelector('input[placeholder="Email here"]').value; } ``` **b. Subscribe button** Give alerts using if else function. ```javascript! if (fullName && email) { const subscription = { fullName, email }; //If the fields have contents, alert success; give alert if field is empty alert("You have successfully subscribed!"); } else { alert("Please fill in both Full Name and Email fields."); } ``` ---

    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