Lecture 9: JS Objects, DOM Manipulation

To-do for today’s class

Helpful Readings

Slides

Link to download PDF version.

Completed Files

Lecture 8: JS Numbers, Strings, Objects, User Input

To-do for today’s class

Helpful Readings

Slides


Link to download PDF version of slides.

Resources

Completed Files

Lecture 4: Page Layouts

To-do for today’s class

Slides

View Slides

Link to download PDF version.

Helpful Readings

Completed Files

Completed files are stored in a GitHub repository. Links below will take you to a list of file(s) from today’s lecture. You can view the code via the browser through GitHub’s UI or clone/download the repo to open the code from your computer.

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 (Google Drive folder 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 a browser and go to https://303.itpwebdev.com/cpanel (it will redirect you to https://54-148-150-30.cprapid.com:2083/).
  2. Login with your username and password (this password does not sync with your USC NETID password. You set this password in Lab 1. If you don’t remember your password, post on EdStem and a course staff member will reset it for you).
  3. Scroll down to Files section and click on File Manager. You will see a list of folders and files like below.
  4. Double click to navigate inside the public_html folder.
  5. Create a new folder inside the public_html folder by clicking on the +Folder button on the top left.
  6. Name the folder assignment04. Double click it to navigate inside this folder.
  7. Click on “Upload” to upload all assignment4 files to this folder.
  8. Drag and drop all assignment files to upload into this folder.
  9. In your browser, go to http://303.itpwebdev.com/~yourusername/assignment04/tshirt-customizer.html to check that the assignment file has been uploaded correctly.
  10. One last thing. In your computer, open up student_page.html that you created in Lab 2. Add a link to this assignment to student_page.html under the heading “Assignments” so that the graders can easily access your completed assignment.
  11. Re-upload the updated student_page.html to the itpwebdev server via cPanel -> Files -> File Manager. If it asks you want to overwrite the previous file, click Yes.
  12. If all the above is completed, go to your student page at http://303.itpwebdev.com/~yourusername/student_page.html and check that the link to this assignment is there. The TAs/graders use this link to access your assignment so make sure this is working! Below is a screenshot sample of what it should look like.
  13. (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.

Lecture 7: CSS Positions, JS Events and Traversal

To-do for today’s class

Helpful Readings

Slides

Link to download PDF version of slides.

Completed Files

Lab 4: 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 Google Drive link.
  2. Do not change the HTML or the styles.css file.
  3. 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.
  4. Write all CSS and JavaScript in gallery.html.
  5. Review the HTML structure. Note that name of each thumbnail’s name is in a child div.
  6. Write CSS in the <style> tag so that when a user hovers over a thumbnail:
    1. Name of the place is displayed on top of the thubmail. Use CSS position property to achieve the overlapping effect.
    2. Change the text color of name to white.
    3. Change the background color of name to a slightly transparent black. Background width is as wides as the thumbnail.
      1. Hint: Use rbga() as background color to make background color slightly transparent.
    4. Position the name so that it is displayed at the bottom of each thumbnail.
  7. Write JS in the <script> tag so that when a user clicks on a thumbnail:
    1. Update main image to clicked thumbnail image.
      1. Hint: Refer to this article to see the various traversal properties. Use console.log() to log out different traversal properties.
    2. Update main image’s alt attribute to clicked thumbnail’s alt attribute.
    3. Update the caption below the main image to the clicked thumbnail’s alt attribute.

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 a browser and go to https://303.itpwebdev.com/cpanel (it will redirect you to https://54-148-150-30.cprapid.com:2083/).
  2. Login with your username and password (this password does not sync with your USC NETID password. You set this password in Lab 1. If you don’t remember your password, post on EdStem and a course staff member will reset it for you).
  3. Scroll down to Files section and click on File Manager. You will see a list of folders and files like below.
  4. Double click to navigate inside the public_html folder.
  5. Create a new folder inside the public_html folder by clicking on the +Folder button on the top left.
  6. Name the folder lab04. Double click it to navigate inside this folder.
  7. Click on “Upload” to upload all assignment4 files to this folder.
  8. Drag and drop all assignment files to upload into this folder.
  9. In your browser, go to http://303.itpwebdev.com/~yourusername/lab04/gallery.html to check that the assignment file has been uploaded correctly.
  10. One last thing. In your computer, open up student_page.html that you created in Lab 2. Add a link to this assignment to student_page.html under the heading “Assignments” so that the graders can easily access your completed assignment.
  11. Re-upload the updated student_page.html to the itpwebdev server via cPanel -> Files -> File Manager. If it asks you want to overwrite the previous file, click Yes.
  12. If all the above is completed, go to your student page at http://303.itpwebdev.com/~yourusername/student_page.html and check that the link to this assignment is there. The TAs/graders use this link to access your assignment so make sure this is working! Below is a screenshot sample of what it should look like.
  13. (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/Labs -> Lab 4: Photo Gallery. You will get some points deducted for not uploading correctly but at least you will not get a zero.

Lecture 6: Bootstrap continued, Intro to JavaScript

To-do for today’s class

Helpful Readings

Slides


Link to download PDF version.

Completed Files

Lecture 3: IDs, Classes, div Tag, CSS float

To-do for today’s class

Slides

View Slides

Link to download PDF version.

Helpful Readings

Completed Files

Completed files are stored in a GitHub repository. Links below will take you to a list of file(s) from today’s lecture. You can view the code via the browser through GitHub’s UI or clone/download the repo to open the code from your computer.

Lecture 5: Flexbox, CSS Frameworks, Bootstrap

To-do for today’s class

Helpful Readings

Slides

Link to download PDF version of slides.

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

Until the server is fixed, submit all files to Blackboard. Follow the below steps:

  1. Rename the folder that contains all your A3 files to: ITP303_Assignment3_[usc username]
  2. Compress this folder to a .zip file.
  3. On Blackboard, go to Assignments -> Assignment 3: Bootstrap Company Site and upload the .zip file here.
  4. You will be able to make unlimited submissions. Only the last submission will be graded.

Sample

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