Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I simplify my javascript program with variables!

    Hi i made a script that rotates a picture each monday on my websie but I only knew how to make it so it changes the picture for every monday in JULY. I would like the program to change the picture each monday for the whole year not just one month. I was thinking to make labels for each month in the script but I don't know how to use the LABEL command properly, how can i use the LABEL command? Does LABEL work like it did in Batch files created in dos?. Is there a way to use Variables so that the script will be smaller and it can read what month it is now and when it's monday and when it's not monday? if you know how can you give me some examples?


    thank you



    <script>
    <!--
    myDate = new Date()
    kurwa = myDate.getDate()
    if (kurwa==1)
    document.write('<p align="center">MONDAY</p><div align="center"><img src="mon1.JPG"></div>');
    pizda = "mon1.JPG"
    if (kurwa==2)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==3)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==4)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==5)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==6)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==7)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==8)
    document.write('<p align="center">MONDAY</p><div align="center"><img src="mon2.JPG"></div>');
    pizda = "mon2.JPG"
    if (kurwa==9)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==10)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==11)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==12)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==13)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==14)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==15)
    document.write('<p align="center">MONDAY</p><div align="center"><img src="mon3.JPG"></div>');
    pizda = "mon3.JPG"
    if (kurwa==16)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==17)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==18)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==19)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==20)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==21)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==22)
    document.write('<p align="center">MONDAY</p><div align="center"><img src="mon4.JPG"></div>');
    pizda = "mon4.JPG"
    if (kurwa==23)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==24)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==25)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==26)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==27)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==28)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==29)
    document.write('<p align="center">MONDAY</p><div align="center"><img src="4.jpg"></div>');
    pizda ="4.jpg"
    if (kurwa==30)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    if (kurwa==31)
    document.write('<p align="center">ITS NOT MONDAY OLD PICTURE</p><div align="center"><img src="'+pizda+'"></div>');
    //-->
    </script>

  • #2
    New to the CF scene
    Join Date
    Jul 2002
    Location
    Oxford, England
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey

    This should work..


    Code:
    <script language="JavaScript" type="text/JavaScript">
    var myDate = new Date() //change for testing - e.g. new Date("Aug 17 2002"), new Date("Nov 21 2002") etc.
    //-------------------------------------------------------------------------------------------------------
    var j="Jan 1 "+myDate.getYear();j=new Date(j)
    n=Math.floor(((myDate.getTime()-j.getTime())/86400000+j.getDay())/7)
    m=myDate.getDay()!=1?"ITS NOT MONDAY OLD PICTURE":"MONDAY"
    //-------------------------------------------------------------------------------------------------------
    document.write("<p align='center'>"+m+"</p><div align='center'><img src='mon"+n+".JPG'></div>")
    </script>

    Basically, you would need an image for every Monday of the year (i.e. up to 52). This script then checks how many Mondays have past up to the current date - and then writes the image source respectively (i.e. for today - it would write ...src=mon30.jpg, and on the 5th of August ..src=mon31.jpg). Do you follow? It also will write "MONDAY" and "ITS NOT MONDAY OLD" depending on the day of the week...


    Hope that helps - let me know if you need more explaination

    coxy

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    THANKS COXY this helped me a lot (:

    THANKS COXY this helped me a lot (:


    Originally posted by coxy
    Hey

    This should work..


    Code:
    <script language="JavaScript" type="text/JavaScript">
    var myDate = new Date() //change for testing - e.g. new Date("Aug 17 2002"), new Date("Nov 21 2002") etc.
    //-------------------------------------------------------------------------------------------------------
    var j="Jan 1 "+myDate.getYear();j=new Date(j)
    n=Math.floor(((myDate.getTime()-j.getTime())/86400000+j.getDay())/7)
    m=myDate.getDay()!=1?"ITS NOT MONDAY OLD PICTURE":"MONDAY"
    //-------------------------------------------------------------------------------------------------------
    document.write("<p align='center'>"+m+"</p><div align='center'><img src='mon"+n+".JPG'></div>")
    </script>

    Basically, you would need an image for every Monday of the year (i.e. up to 52). This script then checks how many Mondays have past up to the current date - and then writes the image source respectively (i.e. for today - it would write ...src=mon30.jpg, and on the 5th of August ..src=mon31.jpg). Do you follow? It also will write "MONDAY" and "ITS NOT MONDAY OLD" depending on the day of the week...


    Hope that helps - let me know if you need more explaination

    coxy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •