CS problem

profileSwagman888
assignment6_instructions.pdf

1

CS 170 ‐ Computer Applications for Business

Fall 2016 ‐ Assignment 6

Introduction to JavaScript

Due Date Before 11:00 PM - Friday, October 21st, 2016

Accept Until Before 11:00 PM - Friday, October 28th, 2016

Evaluation 15 points

Submit to Sakai Assignment6_answers.html file

To get credit for this assignment:

Upload and submit the Assignment6_answers.html file through Sakai.

Learning Objectives:

This assignment is designed to practice:

1. Basic understanding of JavaScript variables, including;

a The declaration, initialization and assignment processes

2. Obtain user input by via the prompt() function and present output to the user through

the alert() function

3. Data type conversion in variables (strings to numbers, convert to upper case)

4. Use of the conditional if and if/else statements

5. Use of arithmetic and logic operators

6. Use of comments

Directions:

You are provided an html program. Your responsibility is to insert the JavaScript statements

that will solve the problem discussed below, and to comment the html file with the

requested information per the requirements.

For the JavaScript, you will only complete the section inside of the <script> tags that are

located within the provided skeleton program:

<script id="COMPLETE_THIS_SECTION_ASSIGNMENT_6">

Insert your JavaScript code here

</script>

2

Problem to solve:

The Serendipity Booksellers has a book club that awards points to its customers based on the

number of books purchased each month. The points are awarded as follows:

 If a customer purchases 0 books, they earn 0 points

 If a customer purchases 1 book, they earn 3 points

 If a customer purchases 2 books, they earn 7 points

 If a customer purchases 3 books, they earn 12 points

 If a customer purchases more than 3 books, they earn an additional 5 points on top of

the 12 points for each book above 3.

Preferred Customers receive a bonus of double award points.

The Serendipity Booksellers website needs to be updated to ask the customer to enter the

number of books purchased last month, confirm if they are a Preferred Customer, and then

calculate and display the number of award points earned.

Requirements:

For this assignment; 1. Your program will calculate the award points as described above. 2. You will generate HTML comments to add your name, section and TA name. Each on a

separate line within the <Head> tags. This will (should) NOT be visible in the document on the web browser).

3. You will then add JavaScript code to the provided assignment6.html skeleton file within the <script> tags:

<script id="COMPLETE_THIS_SECTION_ASSIGNMENT_6">

/* INSERT YOUR JAVASCRIPT HERE */

</script>

4. A typical program flow would declare the variables needed to solve the problem,

initialize the variables, solicit input, perform the data manipulation and/or calculations

and display the result.

5. Utilize JavaScript comments to explain the steps you are preforming within your code. A

JavaScript comment’s form is:

/* Place your comment between the stars */

6. You will utilize prompt() functions to request input from the customer. Your message

should be descriptive enough to solicit data from someone not familiar with the

assignment.

3

7. You will utilize the alert() function to display your output as a clear and unstandable

message to the customer.

8. Variable names should be descriptive. For example, if a program is calculating the total

charge for a bill at a restaurant, it may have a variable named tipAmount.

9. Utilize at least one if/else statement. Consider using the if/else in determining the

bonus points.

Additional Information:

Since the contents of a text box, which is what the prompt() function generates, is going to be

used in mathematical operations, use the function parseInt() to convert the text to a number.

Otherwise your calculation operations will not perform as expected.

Example: variableName = parseInt(variableName)

To simplify the comparison of solicited text, it is often easier to convert this text to upper case.

Example: variableName = variableName.toUpperCase();

References:

Fluency 6 - Chapter 17 - Fundamental Concepts Expressed in JavaScript

w3schools.com - http://www.w3schools.com/js/default.asp

Firefox Tools - https://developer.mozilla.org/en-US/docs/Tools/Debugger

Lectures’ slides and examples

Recitation Week 6