Next page | Contents page |

Exercise 9 - String and Global methods

Using the astronomical data and your code from the previous exercise:

1. Convert the Greek letter names to their corresponding symbols in HTML. This does not involve looking up numerical codes. Instead make each name all lower case, put an ampersand (&) in front and a semicolon (;) behind. Eg, ζ which will appear in your HTML table as ζ. Do this by writing a JavaScript function, not by manual editing, so it will work with other data presented in the same format.

2. Write functions to convert the coordinate values to single floating point values in degrees before displaying them in the table. Remember that RA is measured in hours, minutes and seconds of time (24 hours corresponds to 360 degrees) but Dec is in degrees, arcminutes and arcseconds.

A nasty thing to watch out for here is that numbers beginning with a zero digit are to be treated as being in base 8 (octal) instead of decimal. You need the optional radix parameter for parseInt().

As a check, RA "13 45 0.0" should become 13.75 * 360 / 24 = 206.25 degrees and Dec "-12 18 0.0" should become -12.3 degrees. RA is always positive but be very careful how you deal with negative Dec values, particularly ones beginning "-00". These are real-life data so you may encounter these kinds of issues again.

Present the converted coordinate values with 4 digits after the decimal point in all cases (Number has a method for this - see w3schools).

Next page | Contents page |