I have received an interesting javascript practice exercise that I'm trying to understand. The problem below (screenshot) needs to be solved with a while loop.
The coefficient of restitution of a ball, a number between 0 and 1, specifies how much energy is conserved when a ball hits a rigid surface. A coefficient of .9, for instance, means a bouncing ball will rise to 90% of its previous height after each bounce. Write a program to input a coefficient of restitution and an initial hight in meters, and report how many times a ball bounces when dropped from its initial height before it rises to a height of less than 10 centimeters. Also report the total distance traveled by the ball before this point. The coefficients of restitution for a tennis ball, basketball, super ball, and softball are .7, .75, .9, and .3, respectively.I'm trying to use the code below to complete this, but it simply hangs.
function code1() < var heightM = getInputOne(); var heightCm = heightM * 100; var coefficient = getInputTwo(); var distance = getInputOne(); var bounce = 0; while (heightCm >= 10) < bounce = bounce + 1; distance = distance + (heightM * coefficient * 2); heightCm = heightCm * coefficient; >console.log(bounce); console.log(distance); >
Here are the functions being called within it
// Return the text in the 'In 1:' box function getInputOne() < var input = getElement("inOne"); return input.value; >// Return the text in the 'In 2:' box function getInputTwo()