Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Is it my IF statements that are causing my varibles to multiply?

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 03-23-2013, 09:32 PM PM User | #1 MrAtoBandMe New Coder   Join Date: Mar 2013 Posts: 55 Thanks: 27 Thanked 0 Times in 0 Posts Is it my IF statements that are causing my varibles to multiply? I am making a game and I want the day to change day by day after each time the player presses a button. For example, "03/21/1741" then "03/22/1741" then "03/23/1741", and so on. It is important to make single digit numbers in this date occur with a zero before the digit(for example, a "7" would be "07" and "3" would be "03"). My javascript function skips around, and then starts multiplying the days by five rather than going one by one. I have been looking at it for hours and can't seem to find what I did wrong, but I assume that I am somehow getting stuck within the loop and that's what is causing the multiplying. This is my function for the date... Code: ```function MorForm() { if(d=="31"){ d="01"; if(m=="10"){m="11"} if(m=="08"){m="09"} if(m=="07"){m="08"} if(m=="05"){m="06"} if(m=="03"){m="04"} if(m=="01"){m="02"} if(m=="12"){ m="01"; y=y+1; } subForm(); }; if(d=="30"){ if(m=="11"){ m="12"; d="01"; subForm(); } if(m=="09"){ m="10"; d="01"; subForm(); } if(m=="06"){ m="07"; d="01"; subForm(); } if(m=="04"){ m="05"; d="01"; subForm(); } d="31"; subForm(); } if(d=="29"){ d="30"; subForm(); } if(d=="28"){ if(m=="02"){ d="01"; m="03"; subForm(); } d="29"; subForm(); } if(d=="27"){d="28"} if(d=="26"){d="27"} if(d=="25"){d="26"} if(d=="24"){d="25"} if(d=="23"){d="24"} if(d=="22"){d="23"} if(d=="21"){d="22"} if(d=="20"){d="21"} if(d=="19"){d="20"} if(d=="18"){d="19"} if(d=="17"){d="18"} if(d=="16"){d="17"} if(d=="15"){d="16"} if(d=="14"){d="15"} if(d=="13"){d="14"} if(d=="12"){d="13"} if(d=="11"){d="12"} if(d=="10"){d="11"} if(d=="09"){d="10"} if(d=="08"){d="09"} if(d=="07"){d="08"} if(d=="06"){d="07"} if(d=="05"){d="06"} if(d=="04"){d="05"} if(d=="03"){d="04"} if(d=="02"){d="03"} if(d=="01"){d="02"} subForm(); }```
 03-23-2013, 11:11 PM PM User | #2 Philip M Supreme Master coder!     Join Date: Jun 2002 Location: London, England Posts: 17,487 Thanks: 200 Thanked 2,471 Times in 2,449 Posts It should be obvious that your code is extremely long-winded, repetitive and inefficient. And wrong. If you want to manipulate dates, you should use the Javascript date object. In your case there is a difficulty as the year 1741 is before the year 1970 which is the start of "epoch time". However, you can overcome this by making the year 2041 for the purposes of the date object, and then subtracting 300 (years) for the final display. If you wished to display the name of the day, you would need to identify a year which began on the same day as 1/1/1741, and use that instead, deducting the appropraite number of years. My understanding is that you wish the displayed date of 03/21/1741 to advance by one day at each click of the button. Code: ```

``` I expect you realise that if the user refreshes/reloads the page, then the date reverts to its starting value. You could use a cookie to carry the last date forward. "I was gratified to be able to answer promptly. I said I didn't know." - Mark Twain, US humorist, novelist, short story author, & wit (1835 - 1910) __________________ All the code given in this post has been tested and is intended to address the question asked. Unless stated otherwise it is not just a demonstration. Last edited by Philip M; 03-23-2013 at 11:26 PM.. Reason: Noticed typo

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 12:24 AM.