BTI220 Lab 1

Lab 1 is due on Wednesday, July 10, 2013, at 7:00am ET.


Lab 1 – fun with functions

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

  1. One program will work with data types, and perform simple operations
  2. The other will work with flow-of-control, while performing simple operations

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

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 1

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 – All About Me

In Scratchpad, save this program as “lab1-me.js”.

The program will statically create a new JavaScript object with information about you, and then output it to the Web Console. Here’s a suggested coding plan:

1. Create a JavaScript object with information about you. You will need at least the following:

  • Your name (which can be a combined field for your first name and last name, if you wish)
  • Your Seneca student identifier (which is a nine-digit number that begins with a zero)
  • Your birth day, as a Date object
  • All semester-2 courses (there are five of them, four core plus an LSO), as an array of course codes

2. Create a JavaScript function, which will output your info to the Web Console. The function will accept one parameter, which is (will be) the object that you created above in Step 1.

3. Call the function, and pass along the object that you created in Step 1 as a parameter.

Please note the following: The function must produce output that looks like the following example:


You must calculate your age in years, based on the difference between today and your birth day. Use Date and Math methods. Look for a Date method that works with differences, and then think through a solution. Look for a Math method that discards the decimal portion of a decimal number.

Your code will loop through the collection of courses.

Pay attention to the string formatting.


JavaScript Program #2 – Triangle Area Calculator

In Scratchpad, save this program as “lab1-calculator.js”.

This program will calculate the area of a triangle, and use prompt and alert to communicate with the user. Use Heron’s Formula to calculate the area of a triangle. Look for a Math method that will help. Here’s a suggested coding plan:

1. Write a JavaScript function that will perform the calculation.

It will accept one string parameter, which the user enters at the keyboard. The format of the string is number,number,number where “number” is an integer or decimal. (In other words, three numbers, separated by commas.)

It will return the calculated result, if the user input is valid. Otherwise, it will return zero (0).

In the function…

  • The incoming data is a string with comma-separated values – look for a String method to split this into an array
  • Then, make sure each array element is transformed into a string – parseInt may not be suitable, so you may want to look at the + unary operator
  • Do enough data validation to enable you to calculate a correct result, or return zero (0)
  • If you cannot calculate a correct result, write a message to the Web Console (in addition to returning zero)

2. Write a work flow (a loop of some kind) that will prompt the user to enter data, and then call the function from Step 1, while passing on the data.

The result of the function call will be used to alert the user of the result. Format the answer to four (4) decimal places.

This loop continues until the user submits empty data (at the prompt dialog) or cancels out of the prompt dialog. You’ll have to look at the documentation to see what’s returned in those situations, and code accordingly.

The following screen shots show your professor’s working example.

Valid data:

calculator1 calculator2 calculator3

Invalid data:

calculator4 calculator5


How to submit your work

Save both programs in one single compressed file, and use the 7-zip program to create “lab1.7z”.

Use My.Seneca (Blackboard), and locate the “Lab 1…” 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: