this loop isn’t return what the test require. the test require where do the num belong, not the number lower than the num
for(let i = 0; i < arr.length; i++){
if(arr[i] < num && arr[i + 1] > num){
console.log(arr[i])
return arr[i]
}
}
looking at your code your logic is sound. you are trying to stop after finding the lower number by returning it, then assign lower number position.
if so remember that for loop is increasing the value of i, and i is compared to arr.length, so you can use i to know the position of the lower number.
although the logic is sound, this isn’t how return work for more
return stops the function after returning a value
so remove return in the for loop then add console.log(arr.length) after the for loop.
this won’t let you pass the test, but at least you now know, where was the trouble.
this is last edit, I hope🤣. although if(arr[i] < num && arr[i + 1] > num)
passes the description examples, the step requires more from you. you have to keep in mind, what if element in the array equals to num, or what if the array is empty
How am I losing my ability to use comprehensive english by the day, while spending 3 days trying to fix typos in the repo🤦