In both conditions the while loop should evaluate to true.
The loop variable is variable is set to be less than h and greater than zero.
function snailClimb(){
var h = 6;
var u = 3;
var d = 1;
var f = 10;
var result = 0;
var dayTravel;
var container = [];
var initialDay = u - d;
container.push(initialDay);
var travel = u;
var totalDistance;
totalDistance = container.reduce((prev, curr) => prev + curr );
while( totalDistance < h && totalDistance > 0) { // BEFORE IT WAS || instead of &&
dayTravel = travel - (travel * (f/100));
if (dayTravel !== 0){
container.push(dayTravel);
}
travel = dayTravel;
container.push(-d);
result++;
totalDistance = container.reduce((prev, curr) => prev + curr ); // this was added as well.
}
console.log(totalDistance);
console.log(result);
}
snailClimb();
totalDistanceis never updated inside the loop so once it enters the condition will always stay truetotalDistanceinside the loop; you still have to do it before, but also inside.