Starting from:

$30

WEB222-Assignment 1 Solved

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  
In a comment section, describe the following terms with examples (Your code example may appear in comments). a) Infinity

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.

Log the final value in the web console (400 is the final value for the third call).  

More products