As I discussed previously, as I’ve been posting these blogs I’ve found errors in my code.  Mostly they are syntax issues, as I posted without running it (I know, I’m a horrible person).  Another is a sign of something that I still have to work on, remembering where to return information from a function.

Edits on entry: Some simple functions to adjust my time formatting

Here I posted that a lessthanten() function that would not have returned any information.  This is because I placed the return inside of my if block instead of outside it.  Thus instead of this code:

        function lessthanten (x) {

if (x < 10){

 x = "0" + x;

return x;

};

        };

The code should look like this:

        function lessthanten (x) {

if (x < 10){

 x = "0" + x;

};

return x;

        };

The other problems I had with my code, was realizing that my adjusthour() function wouldn’t work the way I wanted to with python syntax.  Almost every language returns information differently from their functions.  My problem came from not understanding how to return multiple pieces of information in javascript.  I originally wrote my return statement in the adjusthour() function to look like this:

function adjusthour (hour) {

...

 return hour, ampm;

};


You can’t use simple comma separation when returning in javascript, you must return a list instead.  This meant I also had to adjust how I called on the information returned from this function.  Thus my return from the function actually looks like this:

function adjusthour (hour) {

...

 return [hour, ampm];

};


Then to call on the information I had to refer to the variable I assigned, and then designate the position in the list I was accessing.  This is shown below using hours as an example:

   var hour = schedule[i].datetime.getHours();
   hourampm = adjusthour(hour);
   hour = lessthanten(hourampm[0]);

As you can see I had to refer to the position within the hourampm list in order to access the hour I created therein.  I also realized, during this process, that there was an even easier way to write some of my repeating code.  For example, when accessing the minutes data I could have made the following two lines of code:

   var minutes = schedule[i].datetime.getMinutes();
   minutes = lessthanten(minutes);  

into simply this:

   var minutes = lessthanten(schedule[i].datetime.getMinutes());  

Thus ends my recent code-realizations.

Up Next Time: What your reading choices could be saying about you