Description
Assessment Weight:
6% of your final course Grade
Objective:
Practice JavaScript basic syntax, built‐in functions, and user defined functions.
Specification:
Write a JavaScript program assignment01.js to perform the following tasks. No validation is required for user input – assume that the user will enter valid information.
Create comment line(s) for each of the Tasks using block comments, indicating the start point of each Task. e.g.
/*****************************
* Task 1
*****************************/
Task 1: Description as Comments
b) Undefined
c) NaN
Task 2: Conversion
a) Using appropriate method, convert 1010 (binary) to decimal, AF (hex) to decimal and 713 (Octal) to decimal. Output appropriate messages to the console for each conversion.
Task 3: Celsius and Fahrenheit temperatures a) Store a Celsius temperature in a variable.
b) Convert it to Fahrenheit and output: “???C is ???F”. //??? Represents the value
c) Store a Fahrenheit temperature into a variable.
d) Convert it to Celsius and output: “???F is ???C.”
Note: visit www.manuelsweb.com/temp.htm for temperature conversion formula.
Task 4: Larger or largest number
a) Write a function named largerNum using the declaration approach, the function:
takes 2 arguments, both numbers, returns the larger (greater) one of the 2 numbers.
b) Write a function named greaterNum using the expression approach, the function:
takes 2 arguments, both numbers, returns the greater (larger) one of the 2 numbers.
c) Call these functions twice with different number parameters, and log the output to the web console with descriptive outputs each time (e.g. “The larger number of 5 and 12 is 12.”).
Task 5: Evaluator
a) Write a function named Evaluator using the declaration approach, the function:
takes unknown number of arguments which are all number scores, returns true if the average of these number scores is greater than or equal to 25. Otherwise return
false.
b) Call this function 3 times with different number parameters, and log the output to the web console with descriptive outputs each time (e.g. “Average grater than or equal to 25: false”);
Task 6: ShowMultiples
a) Write a function called showMultiples using the declaration approach, the function:
Takes 2 numeric arguments (num, numMultiples) – assume the user is entering valid (positive) whole numbers
Outputs all of the multiples of the num argument from 1 to numMultiples: for example: if num = 5 and numMultiples = 4, the function would output:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15 5 x 4 = 20
b) Call this function 3 times with different number parameters, and log the output to the web console with descriptive outputs each time.
Task 7: Closure/Self Invoking
Use JavaScript Closure/self invoking method to do the following: a) Name the outer function as ‘Increment”.
b) Store 100 as a counter in the outer function.
c) Increment the counter by 100 in the inner function and return.
d) Call “Increment” three times and store the returned value in a variable each time.
e) Log the final value in the web console (400 is the final value for the third call).
Special Note: You are not allowed to use prompt / alert anywhere in your code. All input data should be hard coded so that one run generates uninterrupted output data for all 7 tasks. Make sure output does not throw undefined anywhere.
Lab Submission:
Save your file as assignment01.js. add the following comment declaration with your info at the top of your code (failure to do so will result in zero mark for the entire assignment): /********************************************************************************* * WEB222 – Assignment 01
* I declare that this assignment is my own work in accordance with Seneca Academic Policy. No part of * this assignment has been copied manually or electronically from any other source (including web sites) * or distributed to other students.
*
*
********************************************************************************/
Submit your assignment01.js to the Blackboard / My.Seneca Important Note:
grade of zero (0).
Evaluation Rubric
‘undefined’ in output will result in -0.25 marks)
Criteria Marks
Task 1 0.5
Task 2 0.5
Task 3 0.5
Task 4 0.5
Task 5 1
Task 6 1
Task 6 1
Task 7 1
Reviews
There are no reviews yet.