Values

1,6,6,5

Sorted Values Desc

6,6,5,1

Total

The total value with the smallest removed is: 17





Instructions

#1. Write a function called rollStats that has no parameters and returns an array of numbers. This function will do the following:

  1. Create a locally scoped array with no values in it.
  2. Create a for loop that creates 4 random numbers between 1-6. Use the Proper Random Number function provided.
  3. Store the random numbers in a local array.
  4. Return that array
  5. Examples: rollStats() -> [2,3,4,5] rollStats() -> [1,6,6,5]

#2. Create a function called getStatTotal() that takes an array as a parameter and does the following:

  1. Call the sort function provided to sort the array
  2. Remove the lowest value from the array
  3. Create a for loop to loop through the entire array and add the remaining numbers together. (Note there should only be 3 numbers to add)
  4. Return that value
  5. For example [2,3,4,5] -> [3,4,5] -> 12 [1,6,6,5] -> [6,6,5] -> 17

    StatTotal([2,3,4,5]) -> 12

#3. Tie it together with a visual display

When the button is pressed:

  1. Calls the function from #1
  2. Displays the array on the page (string of comma separated values) in the randomValues Span
  3. Displays the array ordered in descending order in the sortedValues span
  4. Send the array of numbers to the function for #2.
  5. Display the total on the page.