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 Recording

4pm section’s recording started about 40 minutes into the lecture. See below for the full recording of the 12pm’s lecture, which covers the same material.

https://usc.zoom.us/rec/play/K-enZ7FkPjugfTO4ANndL_xJcv0jgtA2fCghFb_GsIOlV4JcO2WfoaoWmqwX0iUURfWLd3pfrdYJWG3Z.LEgmQAhN0Kw5nbWo

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 3: Flexbox Nav

Overview

This lab is intended to give you a basic understanding of how CSS flexbox works and its benefits vs using float in previous lab/assignments.

Sample

Requirements

  1. Create a brand new HTML file named flexbox-nav.html (all lowercase, no spaces).
  2. You may write CSS in either an internal or external stylesheet. No inline styles.
  3. Create a <div> with four <a> inside. The links do not need to go anywhere at this point. Use # as a placeholder for href, like this: <a href="#">
  4. Add some basic styling, such as:
    1. A background color on all the <a>
    2. Hover effect to change background color on all the<a>
    3. Add padding top/bottom on all the <a> to create some spacing on top/bottom.
    4. text-align: center to align all the text to the center
  5. Using only flexbox properties (do not use floats!), style the navigation so that:
    1. Desktop (screen sizes 992px and above):
      1. All nav items are in one row.
      2. All nav items have the same width.
      3. Text is horizontally centered.
    2. Tablet (screen sizes 768px – 991px):
      1. Two nav items per row.
      2. Each nav item takes up half the width of the row.
    3. Mobile (screen sizes 0px – 767px):
      1. One nav item per row.
  6. You do not need to use flex-growth, flex-shrink, and flex-basis properties (which we did not go over in lecture). Using width is enough to satisfy the lab requirements.
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 lab03 inside the public_html folder. Then upload this assignment HTML file and images to the lab03 folder. Refer to the guide if you’re not sure how to upload the assignment file.
    1. In your browser, go to http://303.itpwebdev.com/~yourusername/lab3/flexbox-nav.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 3: Flexbox Nav. You will get some points deducted for not uploading correctly but at least you will not get a zero.

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 6: Bootstrap continued, Intro to JavaScript

To-do for today’s class

Helpful Readings

Slides


Link to download PDF version.

Completed Files

 

Lecture 5: Flexbox, CSS Frameworks, Bootstrap

To-do for today’s class

Helpful Readings

Slides

Link to download PDF version of slides.

Completed files

Lecture 4: Responsive Web Design

To-do for today’s class

Slides


Link to download PDF version of slides.

Lecture 4 Continued

Completed Files