# A gaming company is working on a platformer game. They need a function that will compute the character's final speed, given a map and a starting [closed]

## Link to the question i am trying to solve this problem in javascript. if given this calculateFinalSpeed(60, [0, 30, 0, -45, 0]) it should print 75 this is what i tried in java public class GamePlatform { public static double calculateFinalSpeed(double initialSpeed, int[] inclinations) { double currentSpeed = initialSpeed; for (int angle : inclinations) { if (angle > 0) { // Uphill: Reduce speed currentSpeed *= (1 - angle / 100.0); } else { // Downhill: Increase speed currentSpeed *= (1 + Math.abs(angle) / 100.0); } // If the speed drops to 0 or below, the character loses if (currentSpeed

Link to the question

i am trying to solve this problem in javascript.

if given this calculateFinalSpeed(60, [0, 30, 0, -45, 0]) it should print 75

this is what i tried in java

```
public class GamePlatform {
public static double calculateFinalSpeed(double initialSpeed, int[] inclinations) {
double currentSpeed = initialSpeed;
for (int angle : inclinations) {
if (angle > 0) {
// Uphill: Reduce speed
currentSpeed *= (1 - angle / 100.0);
} else {
// Downhill: Increase speed
currentSpeed *= (1 + Math.abs(angle) / 100.0);
}
// If the speed drops to 0 or below, the character loses
if (currentSpeed <= 0) {
return 0;
}
}
return currentSpeed;
}
public static void main(String[] args) {
System.out.println(calculateFinalSpeed(60.0, new int[] { 0, 30, 0, -45, 0 })); // Expected output: 75.0
}
}
```

but it is also failing !