Mercyhurst UniversityMath DeptDr Williams Home

MIS 370 Client Side Programming

Assignment 2: JavaScript Library

This assignment is due by noon on Thursday, March 15.

Goal

For this assignment, you'll create a personal JavaScript library with useful functions.

Requirements

Part I: Assignment Set Up

NOTE: While this part of the assignment only carries a value of 10% of your grade, all directions must be followed exactly or your assignment may not be collected.
  1. In "public_html/courses/MIS_370/includes" directory, create a file called "library.js". There is no associated html or php file for this assignment.

Part II: Library Functions

  1. Create a function called MStoTime that accepts a single number representing a quantity of time in milliseconds as a parameter, and returns the number of seconds, minutes, hours, and days associated with that input. Your function can return the value in any format you prefer, but it should log the result to the console as well as returning a string or array.

    As an example, the function call MStoTime(123456789) should result in a message to the console indicating that 123456789 milliseconds is equivalent to 1 day, 10 hours, 17 minutes, and 36 seconds.
  2. Create a function called newElement that will simplify the creation of a new HTML element. This function should accept four parameters, in the following order: a string that represents the type of element to create, the string containing the id of the parent element the new element should be appended to, a string that contains the id for the new element, and an object that contains any style properties that should be applied to the element. Note that the style object may contain any number of properties, but each one will be a defined

    As an example, the function call newElement( 'div', 'oldContainer', 'newID', {backgroundColor: 'green', width: '50px'} ) should have the same result as the code below:
    let x = document.createElement( 'div' );
    	x.style.backgroundColor = 'green';
    	x.style.width = '50px';
    	x.id = 'newID';
    document.getElementById( 'oldContainer' ).appendChild( x );
    
  3. Create a function called unsort that will accept an array as a parameter, and return a randomly ``shuffled'' version of that array. You may use any algorithm for shuffling that you would like. Your function should not return the same result every time.

    As an example, the function call unsort([1,2,3,4,5]) could return [3,1,5,2,4] or any other shuffled version of the array.

Part III: Extras

The remaining 15% of your grade will be determined by the overall effort and time you put into the library. test.

Additional Notes

  • Your code should reflect best practices as discussed so far in class. This includes semicolons at the end of lines, indentation of code blocks within functions, etc. Points may be deducted from otherwise functional code if it is poorly written and/or difficult to read. Do NOT minify your code.
  • All CSS should be your own - you are NOT permitted to use frameworks (Bootstrap, Foundation, etc) for this assignment. All extraneous lines of CSS should be removed before your assignment is collected.
  • This is not a group assignment. You are expected to produce your own work and follow the course collaboration guidelines.
  • It is your responsibility to make sure you can access the server and modify your directories. You are not required to access the server from home, but it is highly recommended you attempt a connection if you plan to do any work outside the labs. All assignments in this course will be collected from the server - it is your responsibility to make sure you are able to fulfill this requirement.
  • Your HTML and CSS work should validate and follow best practices.