Orbital Period JavaScript Algorithms and Data Structures

In regards to this challenge, I am having 2 problems.

First, we are provided with the earth’s radius yet the formula doesn’t require this.

I assume it’s linked somehow to the semi-major axis.

Which according to the web is 1.


What am I supposed to do with the radius?

function orbitalPeriod(arr) {
    var GM = 398600.4418;
    var earthRadius = 6367.4447;
    var semiMajorAxis= 1; 

    const result = 2 * Math.PI 
    const result1 = Math.round(Math.sqrt(Math.exp(semiMajorAxis,3)/GM));
    return arr;

I believe I’ve found all the Math. functions in order to complete the challenge.
Please not above I am not trying yet to figure out how to sort through the array with object keys. I am only testing the math portion of the challenge.

So assuming 1 is the semi-major axis, this leads to my section question…

Why am I getting infinity as a result of the const result 1 portion of the calculation?

semi major axis is not one…
the object orbit at a certain altitude, but that is the distance of the object from earth surface, to get the semi major axis which is from the center of the earth you also need the earth radius

It’s component to calculate the semi-major axis? So I need to find that formula next?

This is where I am getting 1 for semi-major axis of the earth:

And it is what the formula is asking for:

The average orbital altitude is the average height for the satellite above the surface of the Earth. This is almost the same thing as the semi-major axis.

You need to be doing the semi-major axis of the Earth-satellite system, not the Sun-Earth system. The semi-major axis of the Sun-Earth system is 1AU, but the semi-major axis of the Earth-satellite system depends upon the orbit of the satellite.

in AU, you are not using AU for the calculation tho

1 Like

I think I’m on the right track now:

r1 being major radius and r2 minor radius of an ellipse.

approximately you could say that the F1-c distance can rapresent the Earth radius, so then you need the altitude of whatever object you are making the calculation for - considering it is different objects you can’t take the semi-major axis as a fixed number but it is to be calculated for each different celestial body

(not true, those are the ellipse’s foci, but it to have a graphic rapresentation of why you need the earth radius)

I’m more confused now.

I don’t think that’s quite right. The earth is at F1. The satellite is on the perimeter of the ellipse. The intuition in this is a bit hard because the connection between average altitude and the semi-major axis is not ‘clean’.

Here is a picture I like:

In the case of the earth apparently, we are dealing with 3 values.

Don’t chase that rabbit hole of different radii.

You want the average radius of the earth and the average orbital altitude. When you use those together, they approximate the semi-major axis of the object.

1 Like

no, the earth radius is a portion of the semi major axis


Ether I need to calculate the semi-major axis. It’s a yes or no type of thing. :slight_smile:

Or FCC is simplifying the challenge and giving you earth radius which is basically a(semi-major) in the following formula :

Uh-huh… it’s a yes type of thing:

If one focus of the ellipse defining the orbit is at the center of the Earth and the average orbital altitude gives you the average distance between the satellite and the surface of the Earth then
______ + ______ = ______

You’re really close here…

1 Like

Ok. So assuming I am drowning in a glass of water. :rofl:

This should work at least for the first test but I am still getting infinity as a result.
I believe the problem lies inside “(Math.sqrt(Math.exp(a,3)/GM))”

function orbitalPeriod(arr) {
    var GM = 398600.4418;
    var earthRadius = 6367.4447; 
    var avgAlt = 35873.5553;
    var a = avgAlt + earthRadius; 

    const result1 = Math.round(2 * Math.PI*(Math.sqrt(Math.exp(a,3)/GM)));
    return arr;
  orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);

This function doesn’t do what you think it does.

Side note, you should never use var. Use const or let instead.

1 Like

take this from the input, don’t hardcode it

1 Like