COMP1231 Web Programming Summer 2021 Due Date: Aug 09, 2021, 11:59 PM Assignment 2 Introduction It's time to put all your JavaScript skills to the test to build an app combining everything you've...

Javascript


COMP1231 Web Programming Summer 2021 Due Date: Aug 09, 2021, 11:59 PM Assignment 2 Introduction It's time to put all your JavaScript skills to the test to build an app combining everything you've learned about JavaScript so far. In this assignment, you are required to build 8 functions. Goals and Outcomes • Reverse engineering the built-in functions and built user define functions • Write decision-making statements and control structures to solve problems • Apply programming logic to solve basic to intermediate problems • Testing and debugging Description In this assignment, you are going to create a JavaScript file containing 8 out of 9 functions. Each function represents one step, and 12.5 marks are assigned to each step (function). The functions you create might be very similar to built-in functions in JavaScript. Each function needs to be considered as an individual problem, and you just focus on that one problem when you code the function. What to implement? • Create only one JavaScript file called STUDENTID-functions.js • All the functions you implement must be placed in that JavaScript file, and you are not allowed to use any other external file or library. Using extra file or library result in zero marks for your assignment. 1. Write a function which receives one argument (string). The function would count and return the number of alphanumeric characters found in that string. function('abc 5} =+;d 9') // returns 6 2. Write a function which adds the equal amount of stars to both end of the receiving string and returns the new string. The number of stars to be added is passed as second argument to this function. For example function(“abc”, 2); // returns ‘**abc**’ 3. Write a function that searches the string (passed as first argument) for the character (passed as second argument) and changes the case for all instances of that char found in string. The function should return the new string as shown in example below: function(‘abRA’, ‘a’) // returns ‘AbRa’ 4. Write a function that receives two arguments (array, oddOrEven) and based on the value of oddOrEven (odd or even), the function will filter out all odd/even numbers and returns a string that contains other elements value separated by hyphen as shown in example below: function([1,’b’, ‘x’,2,3,4], ‘odd’) // returns ‘b-x-2-4’ 5. Write a function that accepts an array and a number. The function would start summing the values of array until the sum is greater or equal to the number passed to the function as second argument. The function would then return the value function([5,1,2, 4],6) //returns 6 function([5,1,2, 4],8) //returns 8 6. Write a function that accepts an array as argument. The function should loop through the array elements and accumulate the sum of ASCII value of each character in element and return the total. For example: function([‘A’, ‘bc’, 12]); // returns 361 which is the sum of 65 + 98 + 99 + 49 + 50 7. Write a function that accepts two arguments (a string array and a character). The function will check each character of the strings in the array and removes the character, regardless of case. If the first letter of the string is removed the next letter must be capitalized. Your function would return the result as one string, where each element of array is separated by comma. E.G. function([“John”,”Hannah”,”Saham”], “h”); // returns ‘Jon,Anna,Saam’ 8. Write a function that accepts two arguments (a string array and a character). The function will check each string in an array and count the number of instances of the character that was passed as second argument, if it is placed in an odd index position in that string, regardless of case. The counts for each element of an array are concatenated as one string separated by hyphen and returned E.G. function([“AaA123Aa”, ”Hannah”, ”1090aambcaA”], “A”); // returns: ‘2-1-2’ 9. Write a function that takes an array of numbers to be used as ASCII representation of characters. The function would return a string of characters, representing each value. For example function([65, 66, 67, 97, 98]) // returns 'ABCab’ Do not use built-in functions You are not allowed to use any JavaScript built-in functions for this project. Below is a sample list of some built-in functions that should not be used: String built-in functions Array built-in functions endsWith() includes() indexOf() lastIndexOf() localeCompare() match() repeat() replace() search() slice() split() startsWith() substr() substring() toLocaleLowerCase() toLocaleUpperCase() toLowerCase() toString() toUpperCase() trim() valueOf() trimLeft and trimRight unshift() valueOf() concat() copyWithin() every() fill() filter() find() findIndex() forEach() indexOf() isArray() join() lastIndexOf() map() pop() push() reduce() reduceRight() reverse() shift() slice() some() sort() splice() toString() Submission (2 steps) Before submitting your work, please ensure your files do not contain any of the following or similar statements: document.write(), alert(), prompt(), console.log(), innerHTML, innerText, document.getElementById(), document.querySelector() and or any calls to your functions. Our tester will call your functions and pass arguments to test the returned value. Your functions must work with the values passed to the parameters in each function. Functions using/returning hard-coded values of your own, will not get marked. 1. Upload both files (your .js and main.html) to the following directory in your GBLearn account: public_html/comp1231/assignments/assignment2/ 2. Login to my.gblearn.com and submit your JavaScript file. Late submission penalty: -20% per day NOTE: Assignments not submitted or uploaded with wrong file/directory name will NOT be marked. To complete and test your assignment locally, you will need to create two files on your local machine: 1. main.html (tester can be copied from https://comp1231.gblearn.com/common/s2021/a2/main.html 2. functions file DDDDDDDDD-functions.js (the Ds must be replaced by your student ID) The tester files will be released closer to the due date so you can test your work before submitting. FYI, To prevent plagiarism, we will be using Moss to detect similarities in code submitted by all students registered for this course: https://theory.stanford.edu/~aiken/moss/ Rubric: Each function must be fully functional and dynamically use the values passed to it as argument. Functions that use hard-coded values will not get mark. There is no partial mark for individual function. 1. Functionality: 40% 2. Logic 40% 3. Best practise 20% a) Logic b) Commenting code as needed, but not overdoing it c) Naming convention (camleCasing) d) Meaningful variable names to avid extra commenting. e) Avoid global variable, always declare local variable. f) Declare all the variables on top • Cleaner code • Provide a single place to look for local variables • Make it easier to avoid unwanted (implied) global variables • Reduce the possibility of unwanted re-declarations • Use w3schools.com as your reference g) Initialize Variables h) Use const when variable value never changes. i) Prefixed the Boolean variable name with is and has (isValid, hasPermission) j) When using switches, make sure to end them with a default case. k) Modularize (one function per task) l) Use === Instead of == m) Don't Use Short-Hand. Add {braces} to if and loop statements, even if they only contain one line of code. n) Ending statements with a semicolon; o) Code readability (indentation and spacing before and after operators, but avoid unnecessary spaces). https://comp1231.gblearn.com/common/s2021/a2/main.html https://theory.stanford.edu/~aiken/moss/
Jul 27, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here