www.webdeveloper.com
Results 1 to 3 of 3

Thread: Functions for Setting Images and Counting Down Days

  1. #1
    Join Date
    Nov 2012
    Posts
    16

    Functions for Setting Images and Counting Down Days

    Ok so here's the exact directions on these functions i need to do

    Complete the code for the following functions in the flowers.js file to provide functionality to the solution page. Once the code is completed, each function will run when the pageSetup() function is called when the body is loaded.


    function displayBanner(currentDate)
    {
    /* get the month from current Date */

    /* Set the imgsource variable to be the defaultLogo
    image */

    /* If month is 12, 1, or 2, set variable imgsource to
    winterLogo or to the defaultLogo if not one of those
    three months */

    /* If month is 3, 4, or 5, set imgsource to springLogo
    or to the defaultLogo if not one of those three
    months */

    /* If month is 6, 7, or 8, set imgsource to summerLogo
    or to the defaultLogo if not one of those three
    months */

    /* If month is 10, 11, or 12, set imgsource to fallLogo
    or to the defaultLogo if not one of those three
    months */

    /* Return the imagesource variable to set the myBanner
    imgSrc attribute to that image*/
    }

    function calcDaysToSale(currentDate)
    {
    /* create a Date object for the 15th of the
    current month */
    /* compute difference in days between currentDate
    And the 15th */
    /* if the difference is positive return that value
    Else return message that the sale is over for this
    month */
    }

    Add a function to the head of the tutorial11solution.htm file to call the functions you created in flowers.js.


    function pageSetup() {
    {
    /* get current Date */
    /* set the banner image source */
    /* set the sale form message input
    to the appropriate message */

    }

    Add an event to the body tag to have the pageSetup() function called when the page is loaded.


    here is the flowers.js file i have so far
    Code:
    <script type="text/javascript">
    
    function displayBanner(currentDate) 
             {
               /* get the month from current Date */
    
    	var month= d.getMonth();
    
      /* Set the imgsource variable to be the defaultLogo
         image */
    
    	<img id="defaultLogo" src="defaultLogo.gif" />
    
               /* If month is 12, 1, or 2, set variable imgsource to
                  winterLogo or to the defaultLogo if not one of those 
                  three months */
    	if (month == 12, 1, 2) { imgsource= "winterLogo.gif"; }
    		else {imgsource = "defaultLogo.gif";}
    
               /* If month is 3, 4, or 5, set imgsource to springLogo 
                  or to the defaultLogo if not one of those three
                  months */
    
    
    	if (month == 3, 4, 5) { imgsource= "springLogo.gif"; }
    		else {imgsource = "defaultLogo.gif";}
    
               /* If month is 6, 7, or 8, set imgsource to summerLogo 
                  or to the defaultLogo if not one of those three
                  months */
    
    	if (month == 6, 7, 8) { imgsource= "summerLogo.gif"; }
    		else {imgsource = "defaultLogo.gif";}
    
               /* If month is 10, 11, or 12, set imgsource to fallLogo 
                  or to the defaultLogo if not one of those three
                  months */
    
    	if (month == 10, 11, 12) { imgsource= "winterLogo.gif"; }
    		else {imgsource = "defaultLogo.gif";}
    
               /* Return the imagesource variable to set the myBanner 
                  imgSrc attribute to that image*/
             }
    
    function calcDaysToSale(currentDate) 
             {
               /* create a Date object for the 15th of the 
                  current month */
    
    	saleDay = new Date ("December 15, 2012");
    	
    
               /* compute difference in days between currentDate
                  And the 15th */
    
    	days = (saleDay - currentDate)/(1000*60*60*24);
    
               /* if the difference is positive return that value
                  Else return message that the sale is over for this 
                  month */
    
    	if days > 0 return days;
    		else alert("Sale is over for this month")
             }
    
    </script>
    and here is the html file

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Carol's Flowers</title>
    <link href="flowers.css" rel="stylesheet" type="text/css" />
       <script type="text/javascript" src="flowers.js"></script>
        <script type="text/javascript">
            function pageSetup() {
             {
               /* get current Date */
    thisDate= dateObj.getDate();
    
               /* set the banner image source */
               /* set the sale form message input 
                  to the appropriate message  */
    
             }
    
    
         </script>
    
    </head>
    
    <body  class="oneColLiqCtrHdr">
    
    <div id="container">
      <div id="header">
        <p><img name="myBanner" id="myBanner" src="" alt="Carol's Flowers" />
          <!-- end #header -->
        </p>
        <div id="links"><a href="#">Home</a> | <a href="#">General Arrangements</a> | <a href="#">Seasonal Designs</a> | <a href="#">Custom Orders</a> | <a href="#">Location</a></div>
      </div>
      <div id="mainContent">
        <table id="mainTable">
        <tr>
           <td width="201"><h1><img src="Flowers.JPG" alt="Random Flowers" width="200" height="255" /></h1></td>
           <td width="687">
        <p>Here at Carol's Flowers, we believe that there is a perfect floral arrangment for every occasion! Take a look around and see if there is anything you like. If we don't already have it, then we will create it for you!</p></td>
        </tr>
        </table>
        <!-- end #mainContent --></div>
      <div id="footer">
        <p> <form name="sale" id="sale">
          Days Until Mid Month Madness Sale : 
          <input type="text" name="saleMessage" id="saleMessage" /></form></p>
        <!-- end #footer --></div>
    <!-- end #container --></div>
    </body>
    </html>
    I'm obviously missing quite a bit. I followed every direction my textbook offered but it clearly didn't get me very far. I've also googled the problems (like anyone would do :P) and haven't found much clarification on how things work, just the codes that do what i need (sort of). Thanks in advance to anyone who offers help

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    Some errors...

    Code:
    function displayBanner(currentDate) 
    {
               /* get the month from current Date */
    	// d ( unknown ) to replace by currentDate 
    	var month= d.getMonth();
    	var imagesource; // a local variable 
    
      /* Set the imgsource variable to be the defaultLogo
         image */
    	// This is not javascript !
    	<img id="defaultLogo" src="defaultLogo.gif" />
    	imgsource = "defaultLogo.gif";// would be better
    	
               /* If month is 12, 1, or 2, set variable imgsource to
                  winterLogo or to the defaultLogo if not one of those 
                  three months */
    	// javascript month : from 0 to 11 !
    	// the syntax is wrong 
    	if (month==11 || month==0 || month==1) {imgsource= "winterLogo.gif";}
    	
    	if (month == 12, 1, 2) { imgsource= "winterLogo.gif"; }
    	//	else {imgsource = "defaultLogo.gif";}// not useful 
    
           // same remarks for all seasons...
    	with autumn 
    	/* Return the imagesource variable to set the myBanner 
                  imgSrc attribute to that image*/
    	return imagesource;
    }
    
           
    
    function calcDaysToSale(currentDate) 
             {
               /* create a Date object for the 15th of the 
                  current month */
    	// 15th december is not the 15th of the current month !
    	saleDay = new Date ("December 15, 2012");
    	// You have to define a new dateObject with the actual date
    	saleDay=new Date(currentDate.valueOf());
    	// and to set the date on the 15
    	saleDay.setDate(15);
    
               /* compute difference in days between currentDate
                  And the 15th */
    
    	days = (saleDay - currentDate)/(1000*60*60*24);
    	// valueOf() and Math.round are better (with daylight saving time : there is not always 86400000 milliseconds in a day !)
    	days=Math.round((saleDay.valueOf()-currentDate.valueOf())/86400000);
    
               /* if the difference is positive return that value
                  Else return message that the sale is over for this 
                  month */
    
    	if (0<days) return days;
    		else alert("Sale is over for this month")
    }
    Use development tools to work seriously ...
    Last edited by 007Julien; 12-05-2012 at 07:12 PM.

  3. #3
    Join Date
    Nov 2012
    Posts
    16
    our instructions were to just use Notepad so i went with that since it's easy. thank you for your help! i get stuck in visual basic mode and end up half-writing my html/javascript codes in vb.net lol

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles