JavaScript Assignment

Dropcy
COMP1231-Assignment13.pdf

College for Women

Department of Information Science

Kuwait University

College of Computing Sciences and Engineering

Department of Information Science

COMP1231

Web Programming

Assignment #1

Due Date: Friday, February 26th, 11:59 pm

Weight: 7% of Final Grade

COMP1231 - ASSIGNMENT 1 2

Table of Contents

COMP1231 Assignment 1 ............................................................................................................................ 3

Function 1: Student Information ................................................................................................................... 4

Function 2: Calculate Change ....................................................................................................................... 5

Function 3: Miles to Kilometers ................................................................................................................... 5

Function 4: Find Min and Max ..................................................................................................................... 6

Function 5: Count Occurrences..................................................................................................................... 6

Function 6: Convert Number Grade to Letter Grade .................................................................................... 7

Function 7: Reverse the Order of the Array .................................................................................................. 7

Function 8: School Days Remaining ............................................................................................................ 7

Function 9: Count Vowels ............................................................................................................................ 8

Function 10: Alphabetical Order................................................................................................................... 8

Submission Procedure and Rules ................................................................................................................ 10

Submission Procedure ............................................................................................................................. 10

COMP1231 - ASSIGNMENT 1 3

COMP1231 Assignment 1 Assignment Type: Individual Assignment 1. Description

In this assignment, you are to develop a JavaScript file that contains the implementation of 10 functions. Each

function is represented as one step, and marks will be awarded on the completion of each step (each function).

Each function is independent and solves a unique problem, as such, treat and implement each function in isolation

of the others, that’s is, you should only focus on one problem at a time.

PLEASE NOTE: Input validation is NOT required for any function parameter – You may assume that all

input parameters provided to your functions, are all valid.

2. Objective

• Write decision-making statements and control structures to solve problems

• Apply programming logic to solve basic to intermediate problems

• Testing and debugging

3. Learning Outcomes: After conducting this assignment students will / will be able to:

1. Acquainted with implementing JavaScript functions 2. Follow instructions, and to implement various requirements

4. Instructions:

1. You are to create ONE JavaScript file which must be named <STUDENT_ID>-functions.js, where

STUDENT_ID represents your student number.

2. The implementation for your 10 JavaScript functions must be completed within your <STUDENT_ID>- functions.js file.

You are NOT permitted to use any external files or libraries. Using any external libraries will result in

a final grade of ZERO for your assignment submission.

3. Your JavaScript functions file must be configured for strict mode (“use strict”)

The pages that follow provide the description of the 10 JavaScript functions that you must implement.

COMP1231 - ASSIGNMENT 1 4

Function 1: Student Information

function _one()

Create a JavaScript function that meets the following requirements:

• Creates the following variables that assign your unique profile information:

o your_name

o number_of_courses (this semester),

o program

o part_time_ job (true/false).

• Create a Boolean variable, set to true or false, based on whether you have a part time job. Store the string

“have” or “don’t have” into another variable, based on the Boolean.

• Display your student information to the cosole (console.log()) as illustrated below:

"My name is ???. I’m in the ??? program. I’m currently taking ??? courses." I ??? have a part

time job.

Where “???” should be replaced with your variable data

COMP1231 - ASSIGNMENT 1 5

Function 2: Calculate Change function _two(cents)

Create a JavaScript function that meets the following requirements:

• Is passed an integer parameter, representing a number of Canadian cents.

• The function uses the parameter to determine the smallest number of Canadian quarters, dimes, nickels and

pennies that are equal to the given (parameter) amount.

• Displays the calculated information as illustrated below:

Function 3: Miles to Kilometers function _three(miles, kilometers)

Create a JavaScript function that meets the following requirements:

• Receives two distances, one distance in miles and the other, a distance in kilometers value.

• Converts the miles to the equivalent kilometer value

• Converts the kilometer value to the equivalent miles

• Displays the calculated information as illustrated below:

COMP1231 - ASSIGNMENT 1 6

Function 4: Find Min and Max function _four( array )

Create a JavaScript function that meets the following requirements:

• Receives an integer array as a parameter

• The function transverses the array to determine the minimum and maximum values in the array.

• Displays the calculated information as illustrated below:

************** STEP 4 **************

Calling _four([-8, -1, -87, -14, -81, -74, -20, -86, -61, -10]);

The minimum value in the array is: -87, the maximum value is -1

Function 5: Count Occurrences function _five(string, char)

Create a JavaScript function that meets the following requirements:

• Accepts two input parameters, a string and a character letter.

• The function determines the number of occurrences of the character in the string.

• Displays the result to the console as illustrated below.

************** STEP 5 **************

Calling _five(“map”, “p”);

The word map has 1 occurrences of the character p

COMP1231 - ASSIGNMENT 1 7

Function 6: Convert Number Grade to Letter Grade function _six( grade )

Create a JavaScript function that meets the following requirements:

• Is passed a numeric grade, calculating and displaying the corresponding letter grade based on:

100 - 90 = ‘A+’, 89 - 85 = ‘A’, 84 - 80 = ‘A’, 79 -76 = ‘B+’, 75 – 73 = ‘B’, 72 – 70 = ‘B-’, 69 – 66 = ‘C+’,

65 – 63 = ‘C’, 62 – 60 = ‘C-’, 59 – 56 = ‘D+’, 55 – 53 = ‘D’, 52 – 50 = ‘D-’, < 50 = ‘F’

• Displays the result to the console as illustrated below.

Function 7: Reverse the Order of the Array function _seven(array)

Create a JavaScript function that meets the following requirements:

• Receives character array

• The function reverses the order of the of the character array.

• Displays the results to the console as illustrated below:

************** STEP 7 **************

Calling _seven([j, p, g, F, c, x, A, c, q, I]);

Original order array = [j, p, g, F, c, x, A, c, q, I]

Reversed order array = [I, q, c, A, x, c, F, g, p, j]

Function 8: School Days Remaining function _eight()

COMP1231 - ASSIGNMENT 1 8

Create a JavaScript function that meets the following requirements:

• Receives no input parameters

• Determines the number of days until the end of the school year

• Please note the last day of the W2021 School Calendar is: Friday, April 23rd, 2021

• Displays the result to the console as illustrated below

Function 9: Count Vowels function _nine(word)

Create a JavaScript function that meets the following requirements:

• Accepts a string parameter, counting the number of vowels within the string.

• The function should be case insensitive, handling both upper and/or lowercase letters.

• Displays the result to the console as illustrated below.

************** STEP 9 **************

Calling _nine(“flugelhorn”);

Vowel count: A=0, E=1, I=0, O=1, U=1, Y=0

Function 10: Alphabetical Order function _ten(my_string)

Create a JavaScript function that meets the following requirements:

COMP1231 - ASSIGNMENT 1 9

a. Create a JavaScript function that accepts a string parameter, then organizes the string so it’s in alphabetical

order.

b. The function is case insensitive, that is, it does not distinguish any difference between upper or lower case. c. Displays the result to the console as illustrated below.

************** STEP 10 **************

Calling _ten(“Sameer”);

The string converted in alphabetical order is: aeemeS

COMP1231 - ASSIGNMENT 1 10

Submission Procedure and Rules

Please ensure to remove all instances of the following from your final submission solution:

• document.write()

• innerHTML()

• alert()

• any commented code

• You should only have one console.log() per function, so any debug related console output that you may have used must be removed

Submission Procedure

1. In order to complete this assignment, you will need to create the following TWO files.

I. <STUDENT_ID>-functions.js As mentioned in the assignment instructions, this is where your functions will be implemented.

A template of this file has been provided to you.

II. main.html This file represents the HTML file that includes and calls your JavaScript file and functions.

You must download and use the main.html file from following location:

https://comp1231.gblearn.com/common/assignmentTemplate/as1/main.html This template

contains instructions as to what exactly needs to be modified in this file.

Students will be required to download

https://comp1231.gblearn.com/common/assignmentTemplate/as1/main.html and add their student

id (matching student_id-functions.js file) and function names.

2. A JavaScript tester file will be made available that you can utilize to assist with the testing of your solution. The file is called s21a1tester.js and is already referenced within the main.html. The test file will call your

functions and help you with the validation of your solution. The file is served from gblearn server, and as a

consequence you will require an internet connection to run the tester.

3. You must upload both your files (main.html and student_id-functions.js) to the following directory in your GBlearn account on or before the due date: /comp1231/assignments/assignment1/

4. You must also submit your JavaScript file on my.gblearn.com under comp1231/assignment 1.

Avoiding this step will result in a mark of ZERO for your assignment submission. All

files/folders must be spelled exactly as specified above (all lowercase without any spaces)

5. Late submissions are graded at a -10% penalty per day (five day maximum)

We are going to use Moss (https://theory.stanford.edu/~aiken/moss/ ) to detect similarities in code among all

students. There will be zero tolerance for plagiarism. Please be aware.

GOOD LUCK!