Introduction

In this assignment you will write a program that tells the user his age, zodiac sign and ruling planets.

Programming Concepts Covered in this Assignment

This assignment will test your skill in the following areas:

  • Writing HTML directly to a web page:
    • HTML table
    • HTML line breaks
    • HTML images
  • Using constants
  • Creating and variables
  • Arithmetic Operators
  • User Input and Output
  • Accessing arrays
  • Using methods of the Math object
  • Using methods of the Array object
  • Using methods of the Date object

About Western Astrology

Archaeological finds from ancient Babylonian civilisations show that Western astrology dates back at least 4000 years. Like Chinese astrology, Western astrology remains a commonly used predictor of the human condition. Western astrology is based on your date of birth.

Clarification

This assignment does not require you to believe or disbelieve in astrology or any of its predictions.

Your Task

High level pseudocode:

1. Input

  • Obtain the user's day of birth.
  • Obtain the user's month birth.
  • Obtain the user's year of birth.

2. Calculations

  • Construct date object for current date.
  • Construct date object for date of birth using year, month and day as separate arguments to the date constructor.
  • Calculate the number of years the user has been alive.
  • Calculate the number of days the user has been alive.
  • Calculate the user's zodiac sign.

3. Output

  • Tell the user how many years and days old he or she is.
  • Use a table to present the following output:
    • Show the user an icon representing their zodiac sign.
    • Tell the user their zodiac sign.
    • Tell the user their ruling planet.

Detailed Instructions

Low level or detailed pseudocode:

Input

  • Obtain the user's day of birth using prompt(). (assume correct return value)
  • Obtain the user's month of birth in the form of an index as follows:
    • Input the month name as a string using prompt(). (assume correct return value)
    • Truncate the user's month to 3 letters.
    • Convert the user's month to lowercase.
    • Use a method of the Array object to obtain the month as a number from 0 to 11. For this, you are expected to use the array SHORT_MONTH_NAME given in the provided template.
  • Obtain the user's year of birth using the function prompt(). (assume correct return value)

Input Validation

Normally user input must validated before it can be used. However, for this assignment you are not required to perform any input validation.

This means you do not need to perform any checks to see that the user input is sensible for this assignment. The program is simply allowed to fail if the user data is invalid.

Calculations

  • Using the year, month and day, construct a date object that represents the users date of birth.
  • Construct a date object to represent the current date and time.
  • Calculate the user's age in years and days.
    • The valueOf() method of a date object will give you the number of milliseconds.
    • Subtracting the date of birth from the current date and time will give you the number of milliseconds. Divide this number by 1000 to give the number of seconds the user has been alive.
    • Dividing the number of seconds by the number of seconds per year, and applying Math.floor() will give the number of years.
    • Subtracting the number of years multiplied by the number of seconds per year will give the number of seconds left over.
    • Dividing the number of seconds left over by the number of seconds per day, and applying Math.floor() will give the number of days.
  • Calculate the zodiac.
    • You are provided with ZODIAC_DAY_MONTH. ZODIAC_DAY_MONTH is an array, where each element corresponds to a month. Use the month of birth to index this.
    • Each of these array elements is itself an array, where each element corresponds to the day of the month. Use the day of birth minus one to index this.
    • The result is the zodiac, which is an integer that can be used to index the provided arrays ZODIAC_NAME, ZODIAC_RULER and ZODIAC_IMG.

Output

  • Output the user's date of birth. The provided template has the array MONTH_NAME contains strings that you should use to get the name of the month.
  • Output the user's number of years and days alive.
  • Output a HTML table from your javascript with:
    • The icon of the zodiac sign (use an "img" tag, and ZODIAC_IMG)
    • The name of the zodiac sign (use ZODIAC_NAME)
    • The planets that are said to rule the zodiac sign (use ZODIAC_RULER).

Order of code in your source code file

  • Use the provided template file for your assignment. It provides useful constants and array constants.
  • Put the Javascript code in a single < script> tag in the < head> tag section of your HTML document. Do not write any HTML in the body of the document. This will be generated by your JavaScript code.
  • In the script order your content as follows:
    • Constants
    • Variables
    • Input
    • Calculations
    • Output
  • Your code must be block commented.
  • Please use a tab size of 4.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.