1. TitleEnter 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. ResultsIV. Conclusion1. 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:
|
<<: 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
Table of contents 1. Implement the component time...
Table of contents 1. Instructions 2. Modifiers 3....
Table of contents 1 Introduction 2 Trigger Introd...
The differences among execute, executeUpdate, and...
Table of contents 1. Introduction 1. What is an i...
When you use HTML div blocks and the middle of th...
I recently started learning the NestJs framework....
Table of contents 1. Event Processing Model 1. Ev...
statement : This article teaches you how to imple...
01. VMware Workstation Pro 15 Download Download: ...
Table of contents introduction scroll Element.scr...
There was no problem connecting to the database y...
Table of contents 1. Build basic styles through E...
Preface Linux has corresponding open source tools...
Preface Recently, I encountered a requirement at ...