javascript holiday function

Forum › Forums › General › Software › javascript holiday function

  • This topic has 2 replies, 3 voices, and was last updated Jun 19-5:59 am by brgs.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #179300
    Fabrizio
    Member

      Hello people, i created this function but it doesn’t work.
      Can you help me find the solution or link me some working functions similar?

      <!DOCTYPE html>
        <html lang="eng">
         <head>
          <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <meta http-equiv="X-UA-Compatible" content="ie=edge">
          <title>Example</title>
              
          <SCRIPT LANGUAGE="JAVASCRIPT">
      var banners = new Array("banner1.jpg","banner2.jpg","banner3.jpg","banner4.jpg")
      var bnrCntr = 0
      function bancycle() {
      bnrCntr = bnrCntr + 1
      if (bnrCntr == 4) {
      bnrCntr = 0
      }
      document.Banner.src = banners[bnrCntr]
      setTimeout("bancycle()",3000)
      }
      
      var holidayCntMsg = "Lascia la festa nelle mani di Midwest Catering"
      var curDay = new Date()
      var tMonth = curDay.getMonth()
      
      function HolidayDays() {
      switch (tMonth) {
      case 2:
      var tHoliday = new Date("Marzo 17, 2026")
      var curHoliday = tHoliday.getTime()-curDay.getTime()
      if (curHoliday > 0) {
      curHoliday = Math.ceil(curHoliday / (1000 * 60 * 60 * 24))
      holidayCntMsg = "Solo "+curHoliday+" giorni al St. Patrick's Day!"
      }
      break
      case 5: case 6:
      var tHoliday = new Date("Luglio 4, 2026")
      var curHoliday = tHoliday.getTime()-curDay.getTime()
      if (curHoliday > 0) {
      curHoliday = Math.ceil(curHoliday / (1000 * 60 * 60 * 24))
      holidayCntMsg = "Solo "+curHoliday+" giorni al 4<SUP>th</SUP> di luglio!"
      }
      break
      case 9:
      var tHoliday = new Date("Ottobre 31, 2026")
      var curHoliday = tHoliday.getTime()-curDay.getTime()
      if (curHoliday > 0) {
      curHoliday = Math.ceil(curHoliday / (1000 * 60 * 60 * 24)) 
      holidayCntMsg = "Solo "+curHoliday+" giorni ad Halloween!"
      }
      break
      case 11:
      var tHoliday = new Date("Dicembre 25, 2026") 
      var curHoliday = tHoliday.getTime()-curDay.getTime()
      if (curHoliday > 0) {
      curHoliday = Math.ceil(curHoliday / (1000 * 60 * 60 * 24)) 
      holidayCntMsg = "Solo "+curHoliday+" giorni a Natale!"
      }
      break
      }
      return holidayCntMsg
      }
      </SCRIPT>
         </head>
      <body onLoad="setTimeout('bancycle()',3000)";>
      
          <h1>Welcome here!</h1>
      <SCRIPT LANGUAGE="JAVASCRIPT">
      var holidayMsg = HolidayDays()
      document.write("<h1><CENTER>"+holidayMsg+"</CENTER></h1>")
      </SCRIPT>
      
      </body>
        </html>
      #179310
      sybok
      Member

        I do not program in Java; my recommendation is to check the code using some automated tools/linters:
        https://lightrun.com/top-10-java-linters/

        BTW, using editor with syntax highlighting can be useful too (I assume that you already use one with this feature).

        #179669
        brgs
        Member

          The moment you dump this into a browser it will tell you “Undefined is
          not an object.” And it’s right: Your document has no object “Banner.”

          What it probably won’t tell you is, that it doesn’t speak italian.
          Your date strings are in the wrong format, though.

          regards, brgs

          Values of B will give rise to dom!

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.