html - Issues with JavaScript clock -


i'm having issue modifying javascript code include seconds on clock displayed. i've tried highlight additions i've made source via \|/\|/ before , after section in both html , javascript. sorry if it's not clear. there isn't way bolden code sections.

i understand html enough:

<body> <div id="wrapper">     <div id="toppadding"><br><br><br><br></div>     <br><br>     <div id="clock">         <span id="hour"></span><span id="colon" class="on">:</span><span id="minute"></span> \|/\|/ <span id="colon" class="on">:</span><span id="second"></span> \|/\|/         <!-- <span id="suffix"></span> -->     </div>     <div id="thedate">         <span id="day"></span>,         <span id="month"></span>         <span id="date"></span>     </div> </div>  <div id="settings" class="icon">     <div id="changefont" class="icon setting"></div>     <div id="changebg" class="icon setting"></div>     <div id="changeclock" class="icon setting"></div> </div> <div id="apps" class="icon"></div>  <script src="clock.js"></script> 

here javascript code (i've removed style modifying section it's not required of question):

        window.addeventlistener('load', init, false);      /* =================================================== */     /* === general utilities ============================= */     /* =================================================== */      function $(selector, parent) { // element(s) shortcut         if ( selector.nodetype ) { // if element, return             return selector;         }          // set parent element search within         if ( !parent ) {             parent = document;         }         else if ( !parent.nodetype ) { // parent given id             parent = $(parent);         }          switch ( selector.charat(0) ) {             case ".": return parent.getelementsbyclassname(selector.substr(1))[0]; break;             case "#": return parent.getelementbyid(selector.substr(1)); break;             case ",": return parent.getelementsbyclassname(selector.substr(1)); break;             case ">": return parent.getelementsbytagname(selector.substr(1)); break;             default:  return parent.getelementsbytagname(selector)[0]; break;         }     }     function checkforclass(nameofclass, element) {         if (typeof element == 'string') { element = $(element); }         if (element && element.classname != '') {             return new regexp('\\b' + nameofclass + '\\b').test(element.classname);         } else {             return false;         }     }     function addclass(nameofclass, element) {         if (typeof element == 'string') { element = $(element); }         if (element && !checkforclass(nameofclass, element)) {             element.classname += (element.classname ? ' ' : '') + nameofclass;         }     }     function removeclass(nameofclass, element) {         if (typeof element == 'string') { element = $(element); }         if (element && checkforclass(nameofclass, element)) {             element.classname = element.classname.replace( (element.classname.indexof(' ' + nameofclass) >= 0 ? ' ' + nameofclass : nameofclass), '');         }     }     function toggleclass(nameofclass, element) {         if (typeof element == 'string') { element = $(element); }         if (element && checkforclass(nameofclass, element)) {             removeclass(nameofclass, element);         } else {             addclass(nameofclass, element);         }     }      /* =================================================== */     /* === clock ========================================= */     /* =================================================== */      var hour, min, colon, \|/\|/ sec \|/\|/ ;      function date() {         var currenttime = new date();          var miliseconds = currenttime.getseconds() * 1000;         settimeout(startclock, miliseconds);          var theday = currenttime.getday();         var thedate = currenttime.getdate();         var themonth = currenttime.getmonth();          switch(theday) {             case 0: theday = 'sunday'; break;             case 1: theday = 'monday'; break;             case 2: theday = 'tuesday'; break;             case 3: theday = 'wednesday'; break;             case 4: theday = 'thursday'; break;             case 5: theday = 'friday'; break;             case 6: theday = 'saturday'; break;         }          switch(themonth) {             case 0: themonth = 'january'; break;             case 1: themonth = 'february'; break;             case 2: themonth = 'march'; break;             case 3: themonth = 'april'; break;             case 4: themonth = 'may'; break;             case 5: themonth = 'june'; break;             case 6: themonth = 'july'; break;             case 7: themonth = 'august'; break;             case 8: themonth = 'september'; break;             case 9: themonth = 'october'; break;             case 10: themonth = 'november'; break;             case 11: themonth = 'december'; break;         }          $("#day").innertext = theday;         $("#month").innertext = themonth;         $("#date").innertext = thedate;          // var thehour = currenttime.gethours();         // var suffix = "am";         // if (thehour >= 12) {         //  suffix = "pm";         // }         // $("#suffix").innertext = suffix;     }      function startclock() {         clock();         setinterval(clock, 1000);     }      function clock() {         var currenttime = new date();         var thehour = currenttime.gethours();         var theminute = currenttime.getminutes();         \|/\|/ var thesecond = curenttime.getseconds(); \|/\|/         if (currentclock12h == 1) {             if (thehour >= 12) {                 thehour = thehour - 12;             }             if (thehour == 0) {                 thehour = 12;             }         }          if (theminute < 10) {             theminute = "0" + theminute;         }          \|/\|/ if (thesecond < 10) {             thesecond = "0" + thesecond;         }         \|/\|/          hour.innertext = thehour;         min.innertext = theminute;         \|/\|/ sec.innertext = thesecond; \|/\|/      }       function blink() {         toggleclass("on", colon);     }      // init     function init() {         hour = $("#hour");         min = $("#minute");         colon = $("#colon");         \|/\|/ sec = $("#second"); \|/\|/          date();         clock();         setinterval(blink, 1000);         addclass('loaded', body);         body.addeventlistener('contextmenu', cycleoptions, false);          $("#apps").addeventlistener('click', function() {             chrome.tabs.update({ url: 'chrome://apps' });         }, false);          $("#settings").addeventlistener('click', function() {             togglesettings();         }, false);          $("#changefont").addeventlistener('click', function() {             cyclefont();         }, false);          $("#changebg").addeventlistener('click', function() {             cyclebg();         }, false);          $("#changeclock").addeventlistener('click', function() {             cycleclock();         }, false);  } 

there 2 obvious errors in code, both in small section

 function clock() {     var currenttime = new date();     var thehour = currenttime.gethours();     var theminute = currenttime.getminutes();     \|/\|/ var thesecond = curenttime.getseconds(); \|/\|/     if (currentclock12h == 1) { 
  1. you have spelled currenttime wrong on line you've added
  2. the variable currentclock12h not defined anywhere (at least in code you've shown us)

in same vane, line:

body.addeventlistener('contextmenu', cycleoptions, false); 

the variable body not defined anywhere in code included.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -