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:
- Create a locally scoped array with no values in it.
- Create a for loop that creates 4 random numbers between 1-6.
Use the Proper Random Number function provided.
-
Store the random numbers in a local array.
- Return that array
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:
- Call the sort function provided to sort the array
- Remove the lowest value from the array
- 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)
- Return that value
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:
- Calls the function from #1
- Displays the array on the page (string of comma separated values) in the randomValues Span
- Displays the array ordered in descending order in the sortedValues span
- Send the array of numbers to the function for #2.
- Display the total on the page.