Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Project 4.

  • Loading branch information...
commit 0e537eb5861dd3196dd9d848e06548f61cdfee24 1 parent 1f8cdb6
@mmpessoa authored
View
BIN  .DS_Store
Binary file not shown
View
BIN  SDI/.DS_Store
Binary file not shown
View
101 SDI/project4/ReadMe.txt
@@ -0,0 +1,101 @@
+Project 4 requirements:
+
+Project 4 is all about string manipulation. This activity is here to provide the video and web link references that you'll need to complete your project. Refer to the Project 4 activity for details on the different string manipulation functions you need to implement.
+I would encourage you to build out stub functions for your project, and then fill them in as you watch the video and do your research on strings. A stub function is just the shell of a function that has the correct name and arguments and a dummy return value:
+
+var makeSandwich = function (bread, meat, toppings) {
+ // TODO: Fill in working code here that builds a sandwich
+ return { };
+}
+
+These stub functions may seem silly, but doing them beforehand helps you get a better idea of everything you'll need to do to finish the project. This will help you manage your time more effectively. Also, the stub functions work, they just don't work correctly. This means you can write code around them, and then come back and fill in the details later:
+
+var pbj = makeSandwich("white", "peanut butter", ["grape jelly"]);
+// pbj is an object that will eventually do something useful
+
+
+Some of the functions you'll need to implement for Project 4 are math-related. Refer to the Project 4 activity for details. This activity is here to provide you with the video and web link resources for your research.
+As with the String Manipulation activity, you are encouraged to stub out your math functions for your project before you begin serious coding.
+
+Your project should be written in the form of a library that uses the Revealing Module Pattern discussed in the Week 3 Public and Private activity. This means that a stub version of your project might look something like this:
+
+var ninjaLibrary = function () {
+ // TODO: add some private variables here
+ var throwingStars, toeShoes;
+ // TODO: add some private methods here
+ var signal = function (message) {};
+ // TODO: reveal the public methods here
+ return {
+ "signal" : signal
+ };
+};
+
+This would allow you to use Ninja-related functionality anywhere in your code:
+
+var ninjaLib = ninjaLibrary();
+ninjaLib.signal("This is a message");
+
+It will be easiest to write and submit a single library for your project, but you may split your code into at most 3 libraries of related methods if you so choose.
+
+
+-=-=-=-=-=-
+
+This assignment, like the last one, is in 3 parts: JavaScript code, Google Drawing flowchart, and Git repository.
+JavaScript code
+
+This part of the assignment works the same as the previous three assignments, but this time without a story or theme. Instead, you're building a library: a collection of functions that you can reuse for future assignments. In the Visual Frameworks course you're going to find yourself doing the same repetitive tasks over and over. The code you write for this assignment will help to alleviate some of that repetition.
+
+The code next month will involve quite a bit of string, number, and array manipulation. For this assignment you're going to build some utility functions to solve some common problems:
+
+String
+
+Does a string follow a 123-456-7890 pattern like a phone number?
+
+Does a string follow an aaa@bbb.ccc pattern like an email address?
+
+Is the string a URL? (Does it start with http: or https:?)
+
+Title-case a string (split into words, then uppercase the first letter of each word)
+
+Given a string that is a list of things separated by a given string, as well as another string separator, return a string with the first separator changed to the second: "a,b,c" + "," + "/" → "a/b/c".
+
+Number
+
+Format a number to use a specific number of decimal places, as for money: 2.1 → 2.10
+
+Fuzzy-match a number: is the number above or below a number within a certain percent?
+
+Find the number of hours or days difference between two dates.
+
+Given a string version of a number such as "42", return the value as an actual Number, such as 42.
+
+Array
+
+Find the smallest value in an array that is greater than a given number.
+
+Find the total value of just the numbers in an array, even if some of the items are not numbers.
+
+Given an array of objects and the name of a key, return the array sorted by the value of that key in each of the objects: "a" + [{a:2},{a:3},{a:1}] → [{a:1},{a:2},{a:3}].
+
+======
+There are twelve functions listed above. Build a library that implements any six of those twelve.
+=======
+
+Google Drawing Flowchart
+
+You will use the Google Docs Drawing web app to create flowcharts that represent your library. You should have one flowchart per function. Some functions will be simpler than others, but each flowchart should explain how the function works to someone who cannot see your code.
+This part of the assignment is graded on how well your flowchart matches your code, its logic, and its correct use of the flowchart symbols.
+
+Git Repository
+
+This assignment will be tracked using Git. You'll need to have the presence of mind to work in small chunks, save often, and work with Git each step of the way.
+
+Make-Up Option
+
+You may use this assignment to make up some of what you lost on points for the first three assignments:
+Implement all twelve functions above. At least ten of them should work correctly, but any that do not work should at least have a solid effort in them. If you don't get at least this far, none of the rest of this list applies.
+Comment the sections of your code that show that you know how to do whatever you lost points for on a previous assignment. If you don't have an explicit comment you won't get credit. For example, if you lost points for not including a nested loop in Deliverable 3, include a comment that says something like:
+
+// MAKEUP: nested loops, deliverable 3
+For each fixed instance you may earn up to ¾ or 75% of the points you lost for that item. So if you lost 8 points for an item on the previous assignment, you can get 6 of them back.
+Your fixed code must work! There is no partial credit per item. In the above example, it's 6 points or nothing.
View
95 SDI/project4/michelle_lib.js
@@ -0,0 +1,95 @@
+/*
+
+Michele M. Pessoa
+25 January 20112
+Deliverable 4
+Theme: Building a code library.
+
+*/
+
+
+var michelleLib = function () {
+ // private methods
+
+
+ //Function to validate email address.
+ //Modified code from http://www.zparacha.com/validate-email-address-using-javascript-regular-expression/
+ var checkEmail = function validateEmail(elementValue){
+ var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
+ //The regular expression above checks to see if the email address starts with alpha-numeric characters.
+ //The email address may contain periods, underscores and hyphens.
+ //There must be an @ symbol. There must also be a period before the top level domain, which can have 2-4 letters.
+ return emailPattern.test(elementValue);
+ };
+
+
+
+
+ //This function checks to see if a URL is valid, i.e. starts with "http" or "https".
+ // Modified code from http://snippets.dzone.com/posts/show/452.
+ var checkURL = function (suspectedURL) {
+ var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
+ //The regular expression above checks to see if the suspected URL starts with http or https or www.
+ return regexp.test(suspectedURL);
+};
+
+
+
+
+ // This function capitalizes the first letter of each word in a string.
+ // Modified code from http://www.codeproject.com/Articles/11009/Proper-Case-JavaScript-Function
+ var titleCase = function (aPhrase){
+ return aPhrase.toLowerCase().replace(/^(.)|\s(.)/g, //The regular expression looks for a space then capitalizes the next character.
+ function($1) { return $1.toUpperCase(); });
+};
+
+
+
+
+ // This function rounds a number up or down to the specified number of decimal places
+ // Modified code from http://www.mredkj.com/javascript/nfbasic2.html
+ var formatDecimals = function (aNumber, decimalPlaces) {
+ var num = aNumber;
+ return num.toFixed(decimalPlaces);
+};
+
+
+
+
+ // This function calculates the days elapsed between two dates.
+ //Modified code from http://blogs.digitss.com/javascript/calculate-datetime-difference-simple-javascript-code-snippet/
+ var calculateDays = function daysBetween(earlierDate,laterDate){
+ var totalDays = laterDate.getTime() - earlierDate.getTime();
+ var elapsedTime = new Object();
+
+ elapsedTime.days = Math.floor(totalDays/1000/60/60/24);
+ //Rounding down and dividing by the number of miliseconds in a day.
+
+ totalDays -= elapsedTime.days*1000*60*60*24;
+
+ return elapsedTime;
+
+};
+
+
+
+
+ // This function takes a string number and makes it a true number.
+ var convertToNumber = function (aStringNumber) {
+ return (aStringNumber - 0); //Subtracting zero converts the string to a number.
+};
+
+
+
+
+
+ //public methods & properties
+ return {
+ "checkEmail" : checkEmail,
+ "checkURL" : checkURL,
+ "titleCase" : titleCase,
+ "formatDecimals" : formatDecimals,
+ "calculateDays" : calculateDays,
+ "convertToNumber" : convertToNumber
+ };
+};
View
34 SDI/project4/pessoa_michelle_assignment4.js
@@ -0,0 +1,34 @@
+/*
+
+Michele M. Pessoa
+25 January 20112
+Deliverable 4
+Theme: Building a code library.
+
+*/
+
+
+var lib = michelleLib();
+
+
+
+console.log (lib.checkEmail("%@b.tv"));
+
+console.log (lib.checkURL("http://www.aol.com"));
+
+console.log (lib.titleCase("javascript and more."));
+
+console.log (lib.formatDecimals(700.13659, 2));
+
+// calculateDays Function example
+function showDays()
+{
+ lastChristmas = new Date(2011, 11, 25, 0, 0, 0);
+ dateCurrent = new Date(2012, 1, 25, 0, 0, 0);
+ elapsedTime = lib.calculateDays(lastChristmas, dateCurrent);
+ console.log("There are " + elapsedTime.days + " days between Christmas and my birthday on February 25.");
+}
+showDays();
+
+
+console.log(lib.convertToNumber("42"));
View
41 SDI/project4/sdi-project4.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Michelle M. Pessoa :: Project 4 :: SDI-1201</title>
+ <link rel="stylesheet" href="sdi.css" type="text/css" />
+</head>
+<body>
+<header>
+ <h1>SDI-1201: Michelle M. Pessoa</h1>
+ <h2>Project 4</h2>
+</header>
+<article>
+<p>The six utility functions I'm attempting to add to my code library are: </p>
+<p><strong>String</strong></p>
+<ul>
+
+ <li> Does a string follow an aaa@bbb.ccc pattern like an email address? </li>
+ <li> Is the string a URL? (Does it start with http: or https:?) </li>
+ <li> Title-case a string (split into words, then uppercase the first letter of each word) </li>
+
+
+
+</ul>
+<p><strong>Number</strong></p>
+<ul>
+
+ <li>Format a number to use a specific number of decimal places, as for money: 2.1 -> 2.10 </li>
+ <li>Find the number of hours or days difference between two dates. </li>
+ <li>Given a string version of a number such as "42", return the value as an actual Number, such as 42. </li>
+
+
+
+</ul>
+</article>
+<footer>
+ <p>25 January 2012, Michelle M. Pessoa</p>
+</footer>
+<script type="text/javascript" src="michelle_lib.js"></script>
+<script type="text/javascript" src="pessoa_michelle_assignment4.js"></script>
+</body>
+</html>
View
34 SDI/project4/sdi.css
@@ -0,0 +1,34 @@
+html {
+ background-color: #E1DFD3;
+}
+body {
+ font-family: "Lucida Grande", "Arial", sans-serif;
+ margin: 1.5em auto;
+ padding: 1.5em;
+ background-color: white;
+ color: #4D4B39;
+ max-width: 35em;
+ border: 0.75em solid #A6A59C;
+ line-height: 1.5em;
+}
+p {
+ margin: 1.5em 0;
+}
+h1 {
+ background-color: #4D4B39;
+ color: #E1DFD3;
+ font-size: 200%;
+ padding: 0.75em;
+ margin: -0.75em -0.75em 0.75em -0.75em;
+}
+h2 {
+ background-color: #4D4B39;
+ color: #88a75d;
+ font-size: 150%;
+ padding: 1em;
+ margin: -1em -1em 1em -1em;
+}
+h1 + h2 {
+ margin-top: -1em;
+ padding-top: 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.