JavaScript gets the constellation name and the zodiac code

Source: Internet
Author: User

The use of regular

The code is as follows Copy Code

To take the zodiac, the parameters must be four-digit years
function Getshengxiao (yyyy) {
var arr=[' monkey ', ' chicken ', ' dog ', ' pig ', ' rat ', ' ox ', ' tiger ', ' Rabbit ', ' dragon ', ' snake ', ' horse ', ' sheep '];
return/^\d{4}$/.test (yyyy)? arr[yyyy%12]:null
}

Calculates the constellation according to the month and date of the birthday.
function Getastro (month,day) {
var s= "Capricorn Aquarius Pisces aries taurus Gemini giant crab lion Virgin libra scorpio Sagittarius Capricorn";
var arr=[20,19,21,21,21,22,23,23,23,23,22,22];
Return S.substr (month*2-(day<arr[month-1]?2:0), 2);
}


Regular performance is not good we can directly judge

The code is as follows Copy Code

function Tostar (date) {
SS = Date.split ("-");
Month= parseint (ss[1], 10);
Date = parseint (ss[2], 10);

if (month = = 1 && Date >=20 | | month = 2 && date <=18) {
Value = "Aquarius";
else if (month = = 2 && Date >=19 | | month = 3 && date <=20) {
Value = "Pisces";
else if (month = = 3 && Date >=21 | | month = 4 && date <=19) {
Value = "Aries";
else if (month = = 4 && Date >=20 | | month = 5 && date <=20) {
Value = "Taurus";
else if (month = = 5 && Date >=21 | | month = 6 && date <=21) {
Value = "Gemini";
else if (month = = 6 && Date >=22 | | month = 7 && date <=22) {
Value = "Cancer";
else if (month = = 7 && Date >=23 | | month = 8 && date <=22) {
Value = "Leo";
else if (month = = 8 && Date >=23 | | month = 9 && date <=22) {
Value = "Virgo";
else if (month = = 9 && Date >=23 | | month = && Date <=22) {
Value = "Libra";
else if (month = && Date >=23 | | month = && Date <=21) {
Value = "Scorpio";
else if (month = && Date >=22 | | month = = && Date <=21) {
Value = "Sagittarius";
else if (month = && Date >=22 | | month = = 1 && date <=19) {
Value = "Capricorn";
}
return value;
}
Alert (Tostar (' 1986-12-05 '));


All right, this is very simple, small series recommend the first method, it is looking good, the latter is not good to see but the performance is better.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.