JavaScript implements constellation query function with detailed code

JavaScript implements constellation query function with detailed code

1. Title

Enter a birthday value in the text box and click the button to display the corresponding zodiac sign for this birthday. Define a function that receives a birthday value (a 4-digit string consisting of month and day, such as "0210", "1225", etc.) and indicates the zodiac sign based on the birthday value.

2. Code

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Zodiac Query</title>
</head>
 
<body>
<p align="center">
	Please enter a birthday value (eg: 0123):
	<input type="text" id="t1">	
	<input type="button" value="Show constellations" onclick="show()"/>
</p>
 
<script>
	function show(){
	var c1=document.getElementById("t1").value; //Get the value in the text box //alert(c1);
	var month=c1.substring(0,2);
	var day = parseInt(c1.substring(2));
	switch(month){
		case "01":
			if(day>19){alert("Aquarius")}
			else alert("Capricorn");
			break;
		case "02":
			if(day>18){alert("Pisces")}
			else alert("Aquarius");
			break;
		case "03":
			if(day>20){alert("Aries")}
			else alert("Pisces");
			break;
		case "04":
			if(day>19){alert("Taurus")}
			else alert("Aries");
			break;
		case "05":
			if(day>20){alert("Gemini")}
			else alert("Taurus");
			break;
		case "06":
			if(day>21){alert("Cancer")}
			else alert("Gemini");
			break;
		case "07":
			if(day>22){alert("Leo")}
			else alert("Cancer");
			break;
		case "08":
			if(day>22){alert("Virgo")}
			else alert("Leo");
			break;
		case "09":
			if(day>22){alert("Libra")}
			else alert("Virgo");
			break;
		case "10":
			if(day>23){alert("Scorpio")}
			else alert("Libra");
			break;
		case "11":
			if(day>20){alert("Sagittarius")}
			else alert("Scorpio");
			break;
		case "12":
			if(day>21){alert("Capricorn")}
			else alert("Sagittarius");
			break;
			
	}
}
	
</script>
</body>
</html>

3. Results

IV. Conclusion

1. First of all, we need to understand the corresponding relationship between constellations and dates:

2. substring(start,end) will return a string containing the substring from start to the end (excluding end);

The parseInt() function parses a string and returns an integer.

This concludes this article about implementing the constellation query function with JavaScript and attached detailed code. For more relevant js constellation query content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • JS simple implementation method to calculate the constellation based on the birthday month and date
  • js date, constellation cascade display code
  • js sample code to judge the constellation according to the date
  • JavaScript calculation of constellation zodiac sign (zodiac sign) sample code
  • js code to automatically obtain the constellation according to the date of birth

<<:  CSS uses the placeholder-shown pseudo-class to achieve the floating text effect of the input box

>>:  Detailed explanation of how to configure openGauss database in docker

Recommend

Vue sample code for implementing two-column horizontal timeline

Table of contents 1. Implement the component time...

Detailed explanation of Vue's sync modifier

Table of contents 1. Instructions 2. Modifiers 3....

Detailed explanation of MySQL database triggers

Table of contents 1 Introduction 2 Trigger Introd...

The difference between MySQL execute, executeUpdate and executeQuery

The differences among execute, executeUpdate, and...

MySQL index principle and query optimization detailed explanation

Table of contents 1. Introduction 1. What is an i...

Solution to the gap between divs

When you use HTML div blocks and the middle of th...

NestJs uses Mongoose to operate MongoDB

I recently started learning the NestJs framework....

Detailed explanation of Javascript event capture and bubbling methods

Table of contents 1. Event Processing Model 1. Ev...

Teach you how to make cool barcode effects

statement : This article teaches you how to imple...

VMware Workstation 15 Pro Installation Guide (for Beginners)

01. VMware Workstation Pro 15 Download Download: ...

An article to help you thoroughly understand position calculation in js

Table of contents introduction scroll Element.scr...

Example of implementing login effect with vue ElementUI's from form

Table of contents 1. Build basic styles through E...

The implementation process of Linux process network traffic statistics

Preface Linux has corresponding open source tools...

How to modify the IP restriction conditions of MySQL account

Preface Recently, I encountered a requirement at ...