Declare a variable named “counter” and assign it an initial value of 10.
- Next, declare another new variable named “numbers” and assign it the initial value of an empty array.
- Now, declare a for loop and configure it so that it runs a total of ten times. Within the loop’s code block, increment the “counter” variable by 73, and push the new value of the “counter” variable into the “numbers” array.
- Below the code for your for loop, console log out the “numbers” array to the console.
- Next, create a conditional statement which checks if the value of the “counter” variable is greater than 740. If the value is greater than 740, console log the string “Maximum array number exceeded”, if the value is not greater than 740, console log the string “Array values within specification”.
- Now, declare a new variable named “stats”. Assign it the value of an empty object literal.
Now that you have completed creating the arguments which will be passed into the function, it is time to create the function!
7a. Declare a function named “getStats”.
7b. Declare two parameters for the “getStats” function, “statsObj” (which will receive an object as an argument), and “numbersArr” (which will receive an array as an argument).
Within the “getStats” function’s code block, create the following functionality:
7e. Divide the value you stored in “arrTotal” by the total number of elements in “numbersArr” to get the average of all numbers in the “numbersArr” and assign that value into a variable named “arrAverage”. Then, assign the value stored in the “arrAverage” variable to a property on the “statsObj” parameter named “averageNum”.
7f. Lastly, return the “statsObj” parameter from the function.
Outside of the “getStats” function, complete the final steps below:
- Call the “getStats” function and pass in the “stats” object and “numbers” array you created in steps 1 – 6 as arguments. Store the object which is returned from the “getStats” function into a variable named “returnedStats”.
- Finally, concatenate the values stored in the “returnedStats” object into appropriate places the following string “The largest number was ### and the average of all the numbers was ###” and console log the completed string to the console.
The post Technical Knowledge Assessment . appeared first on ACED ESSAYS.