JSFiddle - React, Tailwind, and code Playground

by Ian Roberts

JavaScript

//iterating through [key,value] pairs of array with while loop

var arr = [2, 7, 4, 8, 6, 4];
var i = -1; //start at -1 b/c we'll be incrementing by 1 right away in our while loop
var highestNumber; //create highestNumber but no need to assign any value to it, we'll get that from the array

//5 is used becuase we have 6 items in arr and arr[0] is the first value and we want to go through the whole array
while (i < 5) {
  i++; //increment i by 1 number, right off the bat bringing it up to 0 and so on...we'll use this as our arr[key]
  if (arr[i] < highestNumber) {
 		//do nothing if value of arr[i] key is less than highestNumber
  } else {
  	//it is higher so we'll set highestNumber to the value of the current arr[i] key
    highestNumber = arr[i]
  }
  alert(arr[i]) //show us the value of the current key
}
alert('highestNumber is ' + highestNumber);