Mark As Completed Discussion

Now that we have created our array, we need to create two variables for the: 1. Maximum number 2. Minimum number

Minimum Value

Let's take the minimum variable, first we need to set a value for this variable, it cannot be 0.

But why?

As in our array example, all the values are greater than zero including our actual minimum value. Therefore the minimum value of our array will not be correct, it will just print a value of zero when in fact the minimum number inside this array is actually 2!

How do we overcome this?

We set the minimum value to Infinity.

JAVASCRIPT
1let minimum = Infinity

Infinity is a value in JavaScript representing mathematical infinity (∞). It is a number greater than any assignable quantity or countable number. In our case we are using it for comparison since if you compare any value to ∞, the ∞ will always be higher than that number.

Maximum Value

In the case of the maximum value, we will set it to minus Infinity (-∞) because no number is less than -∞.

JAVASCRIPT
1let maximum = -Infinity