Overview

The purpose of this assignment is to give you some practice writing JavaScript code and understanding the building blocks of the language.

This is an individual assignment.

JavaScript

Set up and preparation

Download a zipped copy of the hw02 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 this Part of the assignment.

Start by opening the file in a word editor (like Textwrangler) and edit the top of the file comments to include your name and information.

Your task

In this task, you will calculate the price of purchasing books and magazines, 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. Set the default value to 100.
  • Prompt the user for the number of magazines to order. Set the default value to 20.
  • If the number of books ordered is less than 25, charge $50 per book; otherwise, charge $40 per book.
  • If the number of magazines ordered is less than 25, charge $15 per magazine; otherwise, charge $10 per magazine.
  • Charge a shipping fee of $25 if the total order is under $500. Shipping is free if the total order cost $500 or more.
  • Output the information:
    1. the number of books ordered
    2. the price per book
    3. the number of magazines ordered
    4. the price per magazine
    5. the total number of items
    6. the total cost (without shipping)
    7. the total cost (including shipping)
  • Display that information in the console and on the page. bookstore.html contains a skeleton for displaying this information.
  • Finally, there are two questions about testing your code in the comments. Make sure to answer these questions in the comments.

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

prompt for input display output

Submit your work by uploading hw02 folder in your public_html/cs115-assignments folder, in your personal directory.

Once you've uploaded your work, make sure you check the page on the browser using the URL :

		http://cs.wellesley.edu/~myname/cs115-assignments/hw02/bookstore.html
	

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.

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 on your own . 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 other student. You should not be looking at other's code or showing them yours. If you have obtained help from any source, you must acknowledge their contribution in writing.

Grading

These are the criteria we use to grade 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.
  • Your have answered the questions in the comment section.
  • The bookstore page performs and displays the calculations correctly.