BTI220 Lab 2

Lab 2 is due on Friday, July 12, 2013, at 7:00am ET.


Lab 2 – regexp and more functions

This Lab 2 is fairly simple. You will create two separate small JavaScript programs:

  1. One program will work with regular expressions
  2. The other will work with closures

Both enable you to demonstrate your knowledge about JavaScript language features.

DO NOT do this as a “mechanical” unthinking process.

You can’t build a solution by slapping together some parts. And, you won’t be able to find a similar example and just change a few names to get it working.

You have to THINK! And, you must use reference resources.

Therefore, DO NOT use a search engine in an attempt to locate code snippets that may (or may not) work.



Working on Lab 2

Use the Firefox Scratchpad and Web Console tools.

Follow the coding conventions that you have learned from your professor and from Crockford’s advice.

Although you can consult and/or collaborate with another BTI220 student, DO NOT share code. Your professor aggressively enforces the College’s Academic Honesty policy. DO YOUR OWN WORK!


JavaScript Program #1 – Data Validation

In Scratchpad, save this program as “lab2-regexp.js”.

The program will enable your professor to test your regular expressions for five (5) typical use cases that you will encounter when you begin programming web pages soon.

As was noted in the July 9 class notes, there are many input data tasks that aren’t standardized (in a browser), but the concept and design approach is somewhat standard. For example, we have our own per-app or per-organization standards for user name and password formats, a phone number, and Seneca-specific student identifiers and subject codes.

Create JavaScript regexp objects for each of the following data items:

User name – allow 4-20 characters, letters (mixed case), digits, and . @

Password – allow 4-20 characters, letters (mixed case), digits, and . ! @ # $ % &

Phone number – conform to NANP on Wikipedia, and Government of Canada, Public Works and Government Services, Format for writing telephone numbers

Seneca student identifier – allow digits; most student ID numbers begin with a zero (0) – in other words, this data item is a string of digits, and shouldn’t be treated as a big integer

Seneca subject code – formatted as AAA999 (three letters, three numbers)

Include your own test cases (sample entries).

Get the user input from either the keyboard, or by using variables in your (Scratchpad) program.

Using code comments (i.e. // blah blah), for each regexp, briefly explain each and every component of the regular expression – what it is, what it does. That will prove to your professor that you know what you’re talking about.


JavaScript Program #2 – Closure and Inheritance

In Scratchpad, save this program as “lab2-closure.js”.

The program will enable you to enter your course grades, to create an in-memory transcript. It will use a loop to ask the user for a course and grade, and continue until the user signals that they’re done (by an empty entry for example). As each course and grade is entered, the data is accumulated in a collection (i.e. an array). When data entry is complete, the program will output all course-and-grade items, nicely formatted, etc.

Bonus, worth up to one (1) additional mark – Add code that will calculate the grade point average (GPA), and output it as a number with two decimal places. (Here’s the Seneca Academic Policy info page.)

Here are some coding tips (which may be revised after your professor programs a sample solution):

1. Define an object for a course and grade result. It will have two string properties, course code and your grade. This object will be used as the prototype when you (later) create instances in your code.

2. Define and write a function that manages the (array) collection of course-and-grade results. It will have inner functions that will enable your code to add a new course-and-grade result to the collection, and return the collection of course-and-grade results (as an array). (The “bonus” task will also require a method to calculate the GPA.)

3. Write a work flow (a loop of some kind) that will prompt the user to enter data, and then call the function from Step 2, while passing on the entered data. We suggest that you get the course-and-grade as (for example) a comma-separated string (e.g. btp100,b), and pass it along (if it’s valid) to the function, which will ensure that the data is changed to upper case, create the new course-and-grade object, and add it to the collection. Try to do the work  in the function.

Note about data validation… if you wish, you can use a regular expression to validate a subject code.

This loop continues until the user submits empty data (at the prompt dialog) or cancels out of theprompt dialog, or whatever your design is.

4. At the end, output the contents of the collection to the Firefox Web Console.

(maybe – more to come)


How to submit your work

Save both programs in one single zip/compressed file (.zip or .7z).

Use My.Seneca (Blackboard), and locate the “Lab 2…” item in the “Assignments” area. Upload your work before the due date and time. (The link will disappear after that date/time.)





  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: