Hello I a very new to Javascript and I need to make a code that allows someone to enter a date and it will result in the season that date is in. I am at a loss at what I should do, an if else statement? This is as far as I got, thank you for everyone’s time!
<body>
<h1>Date to Season</h1>
<p align="left">Enter Date:
<input id="season" maxlength="4" size="24"/>
</p>
<input type="button" value="Submit" onclick="Submit()"/><br/>
<textarea cols="40" rows="3" id="output"></textarea></body>
<script type="text/javascript">
function Submit(){
var date = document.getElementById('season').value;
var seasons =
if (
Note, there are saner ways of doing this (for instance, using a date object for instance), that would probably be more useful/flexible, especially if you want to determine by the actual season start/stop date (March 28th, for example). This is just to demonstrate a starting point.
Here’s a very simple example, using a swtich() to return a season according to a numeric month:
http://jsfiddle.net/RtC58/
Here’s a little bit more complex example, showing the short/long month plus the numeric month.
http://jsfiddle.net/RtC58/1/
A little bit different approach could be to create variables for the seasons, use if/else statements (as the OP wants an example of) and find the ‘index of’ the month value in the one of the variables (note I added a
,[comma] to the end of the month to disambiguate 1 from 12 and 1 from 0, etc…).http://jsfiddle.net/RtC58/3/