Lecture 9: JS Objects, DOM Manipulation

To-do for today’s class

Helpful Readings

Slides

Link to download PDF version.

Completed Files

Assignment 5: Movie DB API Search

Overview

For this assignment, you will create a web page that allows users to search for movies and display some basic information about the movie. You will use AJAX to access two (2) different endpoints of The Movie DB API (version 3). You will need to read through this API’s documentation to understand how to work with this endpoint.

Sample

Note: Samples below don’t always meet all the requirements. Make sure to follow the requirements rather than solely relying on the samples.

Requirements

Utilizing the Movie DB API
  1. Go to the Movie DB API documentation at https://developers.themoviedb.org/3/getting-started.
  2. Read the “Introduction” section. You will learn that you need to create an API key to authenticate your API calls. Create an account and obtain an API key as instructed.
  3. The first API request you will need to make is to get the movies that are currently playing in theaters. Click through some of the bolded links on the left sidebar of the documentation (Account, Authentication, Credits, etc). You will see that there are numerous endpoints available. Clicking on any endpoint gives you details about the endpoint such as parameters, responses, etc. Look for the one that sounds like you can call to get movies that are currently playing in theaters.
  4. Once you find the endpoint you need, Movie DB API has a nifty tool that allows you to test out the endpoint with your API key and show the results you would get when calling this endpoint. To access this tool, click on the endpoint then click on the Try it out tab. Enter your API key in the api_key field.
  5. Click on SEND REQUEST button and you should see results in JSON format. Get familiar with the JSON keys that are returned because you will need them. Any errors will be displayed if something is wrong.
  6. Next to the SEND REQUEST button, you will also see the full endpoint (with recommended parameters included). This is the endpoint you want to call.
Layout
  1. Create the following new files:
    1. moviedb.html file for all the HTML,
    2. style.css file for all CSS, and
    3. main.js file for all the JavaScript.
  2. Title at the top of the page.
  3. Search box and submit button.
  4. Text that shows how many movies are displayed and how many movies there are in total.
    1. Ex: Showing 20 of 878 result(s).
  5. A layout that displays the movie’s poster image, title, and release date.
    1. Do NOT use tables.
    2. Mobile (0-767px): show 2 columns per row
    3. Tablet (768px-991px): show 3 columns per row
    4. Desktop (991px and above): show 4 columns per row
  6. When a user hovers over the specific movie, show the movie’s ratingnumber of voters, and synopsis on top of the movie’s poster image.
  7. If the movie does NOT have a poster image, show an image that says “Not available” or similar.
  8. If the movie’s synopsis is over 200 characters, append “…” at the end.
  9. Rating and synopsis must fit on the top of the movie image. Do not let the text go outside the movie image.
  10. Page and text need to be readable. Ensure colors complement each other.
  11. You may use Bootstrap, but it is not required.
JavaScript
  1. Create a separate function named ajax() that will make a request to the API.
    1. Allow the function to take in two parameters – the endpoint and the function that will be called when results are returned.
    2. You will find having this function is useful because you will need to make two AJAX calls for this assignment.
    3. Do not use jQuery’s ajax function if you know what that is. You must use native JavaScript’s XMLHttpRequest object like shown in lecture.
  2. Upon the first load of the page, display movies that are currently playing in theaters.
  3. When user submits a search term, display movies that match the search query.
    1. If no results are found, display an appropriate message.
    2. Do not worry about implementing pagination. You can just display the first page of results.
  4. Number of results shown vs returned must be updated when page first loads and every time a new search term is submitted.
    1. Ex: Showing 20 of 878 result(s).
  5. When displaying movies, must use JavaScript’s .createElement() method to create elements.
Submission/Upload to the server

Please follow the submission requirements below carefully. You will be deducted points for not following submission requirements to the teeth.

  1. Open FileZilla and connect to the itpwebdev server as you have done in Lab 1 (click File -> Site Manager). If you forgot how to connect, follow this guide on how to connect and upload files to the itpwebdev web server.
  2. After you have successfully connected to the itpwebdev server, created a folder (aka directory) named assignment5 inside the public_html folder. Then upload this assignment HTML file and images to the assignment5 folder. Refer to the guide if you’re not sure how to upload the assignment file.
  3. In your browser, go to http://303.itpwebdev.com/~yourusername/assignment5/moviedb.html to check that the assignment file has been uploaded correctly.
  4. One last thing. In your computer, open up student_page.html that you created in Lab 1. Add a link to this assignment to student_page.html under the heading “Assignments” so that the TAs can easily access your completed assignment.
  5. Upload the updated student_page.html to the itpwebdev server via FileZilla inside the public_html folder. If it asks you want to overwrite the previous file, click Yes.
  6. (Optional) If you are having trouble uploading to the server and cannot upload on time, add all files for this assignment in a folder, compress it as a .zip file and upload it to Blackboard. On Blackboard, go to Assignments -> Assignment 5: Movie DB API Search. You will get some points deducted for not uploading correctly but at least you will not get a zero.

Suggested Workflow

There are many ways to implement this assignment. If you don’t know where to start, here’s a suggested workflow:

  1. Register for Movie DB API key, find the first endpoint you need and Try it out to make sure your API key is working.
  2. Create a brand new HTML file. Set up the ajax() function and make a request to the API. Log out the results to ensure you successfully received a response back.
  3. If you get back a successful response, pause on working on the JavaScript for now. Start laying out the page with HTML/CSS. While Bootstrap is not required, it may be helpful in creating the responsive layout.
  4. Although you will need to create movie elements using JavaScript, write out HTML to create a few movies first. Hardcode the title, image, rating, synopsis, etc to ensure the layout meets all the requirements first.
  5. Back to JavaScript! Write JavaScript to create the movie elements. Use console.log() to see which keys you need to use to get the movie’s title, image, rating, etc. Start with creating outer elements first and make your way in. Test incrementally. Don’t try to create everything at once. Use the Inspect Element tool to ensure that you are building elements as you want them to be.
  6. Once all the movies currently in theaters are displayed, the code to display search results is very similar.

Assignment 4: T-shirt Customizer

Overview

This assignment will help you practice JavaScript basics. The HTML and CSS is provided for you. You only need to write JavaScript to implement all the interactivity.

Sample

Requirements

Setup
  1. Download starter files (dropbox link).
  2. Write all JavaScript in the included .html file.
  3. Do NOT modify the HTML.
  4. You can complete this assignment without modifying the included external CSS file but you may modify it if needed.
    1. Note: The starter file utilizes Bootstrap CSS classes.
  5. Do NOT write inline JavaScript.
  6. Open up the Inspect tool as you work on this assignment. Use the Console to catch errors and use the Elements tab to see how the HTML elements change.
Customizer
  1. Text to put on T-shirt
    1. As user types text into the text field, display the text in <div id="tshirt-preview">. The div is already positioned for you so you do not need to modify any CSS.
    2. If user types in more than 20 characters:
      1. Change the message “max 20 characters” text color to red and add a CSS class .is-invalid to the text input. .is-invalid is a Bootstrap CSS class that automatically gives a red border around the input.
  2. Font, font size, and text color
    1. When user selects a different font in the dropdown, change the t-shirt font to that font.
      1. Use onchange event to detect change in the dropdown and slider.
    2. When user changes the font size slider, change the t-shirt font size to that size.
    3. When user clicks on one of the text color boxes, change the t-shirt text color to that color AND add a gray border around the color box that was clicked on (add CSS class .selected to it).
Add to Cart
  1. When user clicks “Add to Cart”:
    1. Validate that “Text to put on T-shirt” input field is not empty and is not have longer than 20 characters. Show a red error message below the button and add .is-invalid class around the text input to display a red border around it. Do not update the shopping cart if validation rules are not met.
    2. Shopping cart: hide the “Cart is empty” message if above validation rules are met.
    3. Shopping cart: show the t-shirt information that is in the <div class="cart-item">.
    4. Shopping cart: Update the subtotal, tax, and total fields accordingly.
      1. Each shirt base price is $20.00.
      2. Tax rate is 9.5%.
      3. In JavaScript, calculating floating points are not always accurate (e.g. 0.1 + 0.2 does not equal to 0.3). There are ways to go around this issue but for this assignment, it is OK if not exact results are returned.
      4. Use .toFixed() to set two digits after the decimal place. There are known rounding issues with .toFixed() but it is OK if rounding is a little off in this assignment.
    5. Shopping cart: Update the quantity by one every time user clicks “Add to Cart.” Subtotal, tax, and total must be recalculated every time the quantity is updated.


Remove from Cart
  1. When user clicks on “Remove from Cart”:
    1. Shopping cart: show the “Cart is empty” message.
    2. Shopping cart: hide the shirt information
    3. Shopping cart: Reset the Subtotal, Tax, and Total to 0 (zero).
Submission/Upload to the server

Please follow the submission requirements below carefully. You will be deducted points for not following submission requirements to the teeth.

  1. Open FileZilla and connect to the itpwebdev server as you have done in Lab 1 (click File -> Site Manager). If you forgot how to connect, follow this guide on how to connect and upload files to the itpwebdev web server.
  2. After you have successfully connected to the itpwebdev server, created a folder (aka directory) named assignment4 inside the public_html folder. Then upload this assignment HTML file and images to the assignment4 folder. Refer to the guide if you’re not sure how to upload the assignment file.
  3. In your browser, go to http://303.itpwebdev.com/~yourusername/assignment4/tshirt-customizer.html to check that the assignment file has been uploaded correctly.
  4. One last thing. In your computer, open up student_page.html that you created in Lab 1. Add a link to this assignment to student_page.html under the heading “Assignments” so that the TAs can easily access your completed assignment.
  5. Upload the updated student_page.html to the itpwebdev server via FileZilla inside the public_html folder. If it asks you want to overwrite the previous file, click Yes.
  6. (Optional) If you are having trouble uploading to the server and cannot upload on time, add all files for this assignment in a folder, compress it as a .zip file and upload it to Blackboard. On Blackboard, go to Assignments -> Assignment 4: T-Shirt Customizer. You will get some points deducted for not uploading correctly but at least you will not get a zero.

Lab 4: JS Photo Gallery

Overview

This lab helps you to solidify the basics of manipulating the DOM with JavaScript and event-based programming with JavaScript. You will create an interactive photo gallery.

Requirements

  1. Download the starter file from this Dropbox link.
  2. Do not change the HTML or CSS code. You only need to write JavaScript.
  3. Do not use inline JavaScript. This is bad practice. Write event handlers like we did in class.
  4. In the browser, open up the console like in the lecture and have it open as you complete this lab. It will be helpful to see errors right away. You can also log things out on the browser to test your code.
  5. When a user clicks on a thumbnail:
    1. Make the clicked thumbnail fully opaque (meaning NOT transparent).
    2. Make all other thumbnails 60% opaque (40% transparent).
    3. Make the border color of the clicked thumbnail red (#F00000).
    4. Make the border color of all other thumbnails black (#000000).
    5. Update main image to clicked thumbnail image.
      1. Hint: try logging out the thumbnail’s children property in the console.
    6. Update main image’s alt attribute to clicked thumbnail’s alt attribute.
    7. Update the caption below the main image to the clicked thumbnail’s alt attribute.
  6. Hint: “Reset” all thumbnails every time a user clicks on a thumbnail. Only change the border and opacity on the thumbnail that was clicked.

Sample

Submission/Upload to the server

Please follow the submission requirements below carefully. You will be deducted points for not following submission requirements to the teeth.

  1. Open FileZilla and connect to the itpwebdev server as you have done in Lab 1 (click File -> Site Manager). If you forgot how to connect, follow this guide on how to connect and upload files to the itpwebdev web server.
  2. After you have successfully connected to the itpwebdev server, upload the entire starter file folder (named lab04) into the  the public_html folder. Make sure the images are uploaded as well.
    1. In your browser, go to http://303.itpwebdev.com/~yourusername/lab04/lab04.html to check that the assignment file has been uploaded correctly.
  3. One last thing. In your computer, open up student_page.html that you created in Lab 1. Add a link to this assignment to student_page.html under the heading “Labs” so that the TAs can easily access your completed assignment.
  4. Upload the updated student_page.html to the itpwebdev server via FileZilla inside the public_html folder. If it asks you want to overwrite the previous file, click Yes.
  5. (Optional) If you are having trouble uploading to the server and cannot upload on time, add all files for this assignment in a folder, compress it as a .zip file and upload it to Blackboard. On Blackboard, go to Assignments -> Lab 4: JS Photo Gallery. You will get some points deducted for not uploading correctly but at least you will not get a zero.

Lecture 7: JS Events and Traversal

To-do for today’s class

Helpful Readings

Slides

Link to download PDF version of slides.

Completed Files

Lecture 6: Bootstrap continued, Intro to JavaScript

To-do for today’s class

Helpful Readings

Slides


Link to download PDF version.

Completed Files

 

Assignment 3: Bootstrap Company Site

Overview

For this assignment, you will create a mobile-first, responsive fake company website (two pages) using the Bootstrap CSS framework. You must create the site using Bootstrap components and Bootstrap’s Grid framework with some customization as needed.

Requirements

Setup
  1. Create two brand new HTML files.
    1. Name one home.htmland the other team.html
    2. Add in the required bootstrap meta tags and the bootstrap CSS file (either relative or absolute link).
  2. Create one brand new CSS file.
    1. Write CSS in this file.
    2. Link this CSS file to both home.html and team.html.
  3. Gather text and images for this assignment. Come up with a fake company name and some text that can describe the company’s product or services. Have fun with it – make up any company you ever wanted to create.
    1. Get free beautiful images at https://unsplash.com/ 
  4. Your site needs to be built using the mobile-first approach (already built in with Bootstrap but any extra CSS you add must follow the mobile-first approach).
  5. Most of the site can be built using what Bootstrap comes with, plus a few customizations. Refer to the Bootstrap documentation and hints listed below.
  6. Check your HTML and CSS syntax. You will be deducted points for any syntax errors, tags not closed/not used, etc.
Homepage (home.html)
  1. Navigation Bar
    1. Displays name of company and at least three links: Home, Team, and one other link.
    2. Clicking on the name of company goes to home.html. Clicking on “Home” goes to home.html. Clicking on “Team” goes to team.html. Third link does not need to go anywhere.
    3. “Home” link is a different color than other three links to indicate user is viewing the Home page.
    4. Nav bar must have a background color that is not the default color. You must overwrite the default background color that comes with Bootstrap.
    5. Hint: Refer to Bootstrap documentation on the Navbar component.
  2. Header at the top includes:
    1. Background image
      1. Use CSS property background-image to include a background image on the header.
      2. You may use background-size: cover; to make the image look good across all screen sizes.
      3. Play around with background-position to position the background image if you’d like.
    2. Company name
    3. Company slogan
  3. Below the header, a featured section that displays text and pictures that showcase at least two features of the company’s product or services.
    1. Each feature has some heading text, a paragraph, and an image.
    2. A line between each feature.
    3. Must use Bootstrap’s Grid system to create the rows and columns in this section (for all screen sizes).
      1. Hint: use .container, .row, and various .col classes (refer to Bootstrap documentation)
  4. Footer on the bottom of the page.
  5. Mobile Devices (0 – 767px):
    1. Single-column layout,
    2. Navbar collapses into a hamburger menu (refer to Bootstrap documentation on how to easily implement this).
    3. Featured section’s order from top to bottom must be Feature 1 heading, Feature 1 description, Feature 1 image, Feature 2 heading, Feature 2 description, and Feature 2 image.
    4. Some spacing around each feature (not edge to edge)
  6. Tablet Devices(768px – 991px):
    1. Navbar expands to show all nav links.
    2. One feature per row.
      1. Alternate order of picture and text per row.
      2. Column that contains feature’s text must not be the same width as the column that contains the feature’s image.
    3. Leave whitespace around each feature (not edge to edge)
  7. Desktop Devices (992px and above):
    1. Layout remains the same. Adjust as necessary.
  8. For each device, adjust font sizes, images sizes, etc. as necessary.
  9. All elements and content need to be readable.
  10.  Feel free to play around with Bootstrap and get familiar with it. Bootstrap is extremely useful and is used widely in industry. You are welcome to add additional features, as long as all requirements above are satisfied.
Team (team.html)
  1. Navigation Bar requirements the same as home.html. Navigation bar must look exactly the same in both home.html and team.html.
    1. “Team” link is a different color than other three links to indicate user is viewing the Team page.
  2. Header remains the same, except the heading must read “Our Team” or similar.
  3. Below the header, display at least three team members. Display each team member’s:
    1. Image
    2. Name
    3. Job title
    4. Short bio
    5. A colored “View more” button (that does not need to link anywhere)
  4. Mobile Devices (0 – 767px):
    1. Navbar and header follow the same requirements as Home page.
    2. One team member per row.
  5. Tablet Devices(768px – 991px):
    1. Navbar and header follow the same requirements as Home page.
    2. Three team members per row.
  6. Desktop Devices (992px and above):
    1. Layout remains the same. Adjust as necessary.
Submission/Upload to the server

Please follow the submission requirements below carefully. You will be deducted points for not following submission requirements to the teeth.

  1. Open FileZilla and connect to the itpwebdev server as you have done in Lab 1 (click File -> Site Manager). If you forgot how to connect, follow this guide on how to connect and upload files to the itpwebdev web server.
  2. After you have successfully connected to the itpwebdev server, created a folder (aka directory) named assignment3 inside the public_html folder. Then upload this assignment HTML file and images to the assignment3 folder. Refer to the guide if you’re not sure how to upload the assignment file.
  3. In your browser, go to http://303.itpwebdev.com/~yourusername/assignment3/home.html to check that the assignment file has been uploaded correctly.
  4. One last thing. In your computer, open up student_page.html that you created in Lab 1. Add a link to this assignment to student_page.html under the heading “Assignments” so that the TAs can easily access your completed assignment.
  5. Upload the updated student_page.html to the itpwebdev server via FileZilla inside the public_html folder. If it asks you want to overwrite the previous file, click Yes.
  6. (Optional) If you are having trouble uploading to the server and cannot upload on time, add all files for this assignment in a folder, compress it as a .zip file and upload it to Blackboard. On Blackboard, go to Assignments -> Assignment 4: Bootstrap Company Site. You will get some points deducted for not uploading correctly but at least you will not get a zero.

Sample

Note: Samples below don’t always meet all the requirements. Make sure to follow the requirements rather than solely relying on the samples.

Lecture 5: Flexbox, CSS Frameworks, Bootstrap

To-do for today’s class

Helpful Readings

Slides

Link to download PDF version of slides.

Completed files