Printing high/low/range array values

Can someone help me understand why my function isn’t returning the highest and lowest elements in an array. I originally set the high and low to arr[0] and try to iterate through the array and changing the values of high and low in comparison to the variable “low” and “high”

function getTheRange(arr){
  var low = arr[0]
  var high = arr[0]
  var newArr = []
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] < low) {
      low === arr[i]
    else if (arr [i] > high) {
        high === arr[i]
  	var range = high - low
    newArr.push(low, high, range)
    return newArr

// Uncomment these to check your work!
console.log(getTheRange([3, 2, 5, 4, 7, 9, 10])); // expect log [2, 10, 8]

Function returns the initially set values of low and high, this suggests something isn’t right with setting them later or with conditions for those. Take a look at that inside of the if/else if blocks.

1 Like

This compares that low and all[i] are the same value. You should use a single = for assignment.