The purpose of this assignment is to get you to think about privacy considerations online and to get some practice writing basic JavaScript code.

This is a team assignment. You are required to work with a partner on both Part 1 and Part 2 of the assignment. See below on how to form teams and submit your common work.

Forming teams

Use this team-forming shared document to form and declare teams.

Part 1: Thinking about Privacy

Studying a specific case

Read this recent NYTime article on how Facebook tinkers with users' emotions in one of its News Feed experiment. Produce, together with your partner, a 200-word response to the following questions:

Do you think the experiment is a violation of user privacy? If so, why? And if not, why not?
Is Facebook the only company that is doing such experiments? Give examples where other companies may be doing something similar.

Meet with yout teammate to discuss and formulate a supportable opinion and write it up, in a Google shared Document. In your answer you are allowed to use hyperlinks to point to relevant resources. Be succinct, be clear be persuasive.

Submit your work by sharing your response document (one document per team) with your professor, and by adding your document's URL here

We may hold an in-class debate about this.

Part 2: Basic JavaScript

Pair programming

On this part, you and your partner will be pair-programming basic JavaScript.

Pair programming, as you have experienced it in lab,  is an agile software development technique in which two programmers (or students) work together sharing one computer. One student is the driver, who controls the keyboard and mouse. The other is the navigator, who observes, asks questions, suggests solutions, and thinks about slightly longer-term strategies. The two programmers switch roles about every 20 minutes.

Working in pairs should make you much better at programming than would working alone. Research shows that the resulting work of pair programming nearly always outshines that of the solitary programmer, with pairs producing better code in less time.

To learn the do’s and don’ts of pair programming and to see pairs in action, view this entertaining video about pair programming from North Carolina State University: An Introduction to Pair Programming for Students.

(The above information about pair programming is adapted from NCWIT)

Set up and preparation

You will need to arrange times to meet with your partner outside of class for pair programming sessions. We expect that your work will be a result of applying the pair programming practices described above.

Download a zipped copy of the hw3 starting folder onto your Desktop and open it by double-clicking on it. This folder contains a file bookstore.html, which you will use for Task 1 of this Part of the assignment, and the files myJSCode.js and assign3.html that you will use for Tasks 2 and 3. Note that you are not allowed to make any changes in the file assign.3.html.

Start by opening the file in a word editor (like Textwrangler) and edit the top of the file comments to include both partners names.

Task 1

In this task, you will calculate the price of purchasing books, using some simple JavaScript input, output, arithmetic, and conditional statements.

Put your JavaScript code at the end of the body of the bookstore.html, within the start and end script tags. First read the whole description and look at the images below. Your code should do the following:

  • Prompt the user for the number of books to order. You can set the default value to 100.
  • If the number of books ordered is less than 25, charge $50 per book; otherwise, charge $40 per book.
  • Charge a shipping fee of $25 if the total order is under $500. Shipping is free if books cost $500 or more.
  • Calculate a tax of 7% on the books cost (do not tax the shipping fee).
  • Report on the console (use console.log()), all the information:
    1. the number of books ordered
    2. the price per book
    3. the cost of the books before tax and shipping
    4. the tax amount
    5. the shipping fee, and
    6. the total cost for the order (including books cost, tax, and shipping).
  • Finally, display that information in an alertpop up window.
  • BONUS: Display the information directly on the page itself, using JavaScript (worth an extra 10%).

NOTE: to format a value so that two digits appear after the decimal point (such as for currency), use the JavaScript toFixed() method (it also rounds up). Here is an example of the use of toFixed() in the console:

toFixed example

Here is the what your page should look like when prompting for an input and then displaying the results:

prompt for input display output

Here is another example, where a lower number of books ordered results in a higher price per book and a shipping fee:

display output

Here is what the page looks like with the BONUS display of results directly on the page:

display output

Task 2 Simple Conditionals

In this task, you will calculate the price of a bulk of books.

In the file in the file myJSCode.js, fill in the code of the function calculateBookCost() {} to do the following:

  • Prompt the user for the number of books to order. You can set the default value of the prompt to 100.
  • Calculate the total price of the books ordered, given that,
    • The price of a single book is $50 if the number of ordered books is less than 25 books.
    • The price of a single book is $40 if the number of ordered books is 25 or more books.
  • Report the total price of the books to the user via the console.log() function.

You can test your code by clicking on the Calculate Book Cost! button in the assign3.html file. Be sure to have the JavaScript console open, so that you will see error messages and the console.log output.

Task 3: More on file calculations

In the file in the file myJSCode.js, fill in the code in function ImageSize() {} to do the following:

  • Prompt the user for an image details by asking for:
    • pixNum which is the total number of pixels in the image.
    • colorNum which is the total number of colors in the image.
  • Calculate the bit depth of the colors in the image by using a cascading if statement to assign the bit depth based on the number of colors (as if you were reading the bit depth from the table below):
    # colors bit-depth (bits/pixel)
    1 - 2 1
    3 - 4 2
    5 - 8 3
    9 - 16 4
    17 - 32 5
    33 - 64 6
    65 - 128 7
    129 - 256 8
  • Calculate the total size of the compressed image. Remember that the file size is the sum of the image size and the color table size (in bytes). The image size (in bits) is the product of the number of pixels by the bit depth. The color table size is determined by the number of colors, but each color needs 3 bytes to be represented (one for each R, G and B component).
  • Report those values in the console (so that you can check your work).
  • Decide on the message to show the user according to the compressed image size:
    • The "Image is too large" message must show if the image file size is larger than 100KB.
    • The "Image is just fine" message must show if the image file size is less than or equal to 100KB.

You can test your code by clicking on the How Big? button in the assign3.html file. Think about how best to test your code and determine some appropriate test cases.

How to submit your work

Submit your work by uploading hw3 folder in your public_html/cs115-assignments folder, in your personal directory. Notice that even this is a team-programming work, both partners need to upload the common work, each one to their own folder in the server (as you have been doing for your lab work).

Once you've uploaded your work, make sure you check both pages on the browser using the URLs :


When you visit the page, because this is in a protected directory, you will be prompted for a username and password. Use your own login name and password for your account on the CS server.

Once tested add your url to the Assignment 3 submission document.

There is no need to validate your code, but you can do so if you wish to.

Due Date/Time

Assignments are due at 11:59PM on the due date (check the schedule). Remember that this policy means that you should not modify work after the due time has passed.

Honor Code

The Honor Code applies to this course. You are encouraged to discuss assignments with other students, the tutors, and with your instructors. However, you must solve, write up, debug, test and document the assignment only with your own partner. In other words, it is acceptable to talk with other students in English (or any other human language), but not acceptable to use any formal language and especially not HTML, CSS or JavaScript with any student but your partner. You should not be looking at other teams' code or showing them yours. If you have obtained help from any source, you must acknowledge their contribution in writing.


These are the criteria we use to grade Part 2 of the homework:

  • Homework was submitted on the server by the due date.
  • Folders and files have the required names and are uploaded to the proper location.
  • Your files have comments at the top and as necessary interspersed in the code.
  • Your code follows our recommended coding style.
  • The bookstore page performs and displays the calculations correctly.

Help Room

Our tutors in the help room can help you with concrete problems and questions you have about the assignment, thus, go to the room prepared. If you find that you don't know how to start the assignment, you should visit the instructors during their office hours.