Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:17:22+00:00 2026-06-08T10:17:22+00:00

I’m new to Javascript and finding some difficulty in a task writing a program.

  • 0

I’m new to Javascript and finding some difficulty in a task writing a program.

My task will be to write a program that will allow a user to enter their date of birth. The program then proceeds to give the corresponding Chinese Zodiac sign in an image and the number of days the user has been alive.

What will be input?

  • The user’s year of birth (assume a valid 4 digit year will be input)
  • The user’s month of birth (assume user will enter at least the first
    three letters of a month name, but this could be longer and could
    contain upper case characters, so it could be jan, Jan, january, or
    January, or other month names)
  • The user’s date (in the month) of birth (assume a valid date will be
    entered)

Constants we will use

Create and appropriately name constants to store the following values:

  • A string containing month
    abbreviations ‘JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC’
  • The number of milliseconds in a day 1000*60*60*24
  • The cycle of Chinese zodiac 12
  • The year initialising Chinese Zodiac cycles 1924

My code so far:

var year = prompt('Enter year of birth as a 4 digit integer') // A prompt to enter the year of birth.
var month = prompt('Enter the name of the month of birth') // A prompt to enter the month of birth.
var date = prompt('Enter day of birth as an integer') // A prompt to enter the date of birth.
    var month = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]
    var month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    var month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
    var month = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]

I’m having trouble with the input of the month of birth. I’m trying to write a code to assume user will enter at least the first three letters of a month name, but this could be longer and could contain upper case characters, so it could be jan, Jan, january, or January, or other month names.

Any help will be appreciated!

George

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:17:24+00:00Added an answer on June 8, 2026 at 10:17 am

    Use .substr() to shorten their input, and .toLowerCase() to convert it to lowercase. Then match it to your array of months (the lowercase version). Here’s a bit to help you get started:

    var month = prompt('Enter the name of the month of birth');
    // Chop everything after the first 3 characters and make it lowercase
    month = month.substr(0,3).toLowerCase();
    // Store your array in months, differently named than the month input
    var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
    
    // You can then use array.indexOf() to locate it in the array
    // Not available in older browsers though
    var pos = months.indexOf(month);
    if (pos >= 0) {
       // valid month, number is pos
    }
    

    P.S. Don’t forget the ; at the end of each statement!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.