Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Your stupidest coding goofs

  1. #1
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Red face Your stupidest coding goofs

    One time, I had to add 12 hours to the current hour and display it on screen in 12-hour time. My first instinct was, believe it or not, to do this:
    Code:
    var hour = new Date().getHours();
    var hours;
    
    switch(hour) {
    	case 0:
    		hours = 12;
    	break;
    	case 1:
    		hours = 13;
    	break;
    	case 2:
    		hours = 14;
    	break;
    	case 3:
    		hours = 15;
    	break;
    	case 4:
    		hours = 16;
    	break;
    	case 5:
    		hours = 17;
    	break;
    	case 6:
    		hours = 18;
    	break;
    	case 7:
    		hours = 19;
    	break;
    	case 8:
    		hours = 20;
    	break;
    	case 9:
    		hours = 21;
    	break;
    	case 10:
    		hours = 22;
    	break;
    	case 11:
    		hours = 23;
    	break;
    	case 12:
    		hours = 0;
    	break;
    	case 13:
    		hours = 1;
    	break;
    	case 14:
    		hours = 2;
    	break;
    	case 15:
    		hours = 3;
    	break;
    	case 16:
    		hours = 4;
    	break;
    	case 17:
    		hours = 5;
    	break;
    	case 18:
    		hours = 6;
    	break;
    	case 19:
    		hours = 7;
    	break;
    	case 20:
    		hours = 8;
    	break;
    	case 21:
    		hours = 9;
    	break;
    	case 22:
    		hours = 10;
    	break;
    	case 23:
    		hours = 11;
    	break;
    	default:
    		hours = "NaN";
    }
    ...

    Ack.

    I am now using this:
    Code:
    var minutes = new Date().getMinutes();
    var hour = new Date().getHours();
    var hours = hour + 12;
    
    if (hours > 23) {
    	hours = hours - 12;
    }
    ...
    Last edited by techno_race; 07-04-2008 at 09:16 PM.
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  2. #2
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    Oh, dang it.
    Code:
    hours = hour
    ...
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  3. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I unlinked() an array once.
    Jeremy | jfein.net

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I have a terrible habit, that I think I'm finally starting to break, of forgetting to include the '[i]'s (highlighted below) or whatever the var is (usually it's 'i') when looping through something like:

    Code:
    for(var b = some_collection_or_array, i = 0; i < b.length; ++i)
    if (b[i].something == 'some_string')
    b[i].something_else = yet_another_thing;
    I think the reason is that in my mind it should just be understood what I'm referring to, though computers rarely work that way.

    I always catch the error(s) sooner (usually) or later, but if I had a nickel for every cumulative hour wasted on this, I'd probably be in a higher tax bracket.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Are you kidding? In that the i is my favorite part!
    Jeremy | jfein.net

  6. #6
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    I'm always get pissed by this:
    Code:
    <script type="text/javascript">
    window.onload=function()
    {document.forms[0].onsubmit=function()
    {var str=document.getElementById('email');
    if (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(str.value))){alert ("Please enter a valid email address.");
    return false;}
    }
    return;
    }
    </script>
    <form action="http://www.google.com">
    <label>Email:</label><input type="text" id="email">
    <input type="button" value="Submit">
    </form>
    Of course, the only mistake was the highlighted, which took me almost an hour to debug the script.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Nile View Post
    Are you kidding? In that the i is my favorite part!
    Mine too, but that doesn't prevent me from too often forgetting it in the evaluation phase of the loop. Though, as I say, I'm getting better at it.
    Last edited by jscheuer1; 07-05-2008 at 01:15 PM. Reason: spelling
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'd say I tend to type function(something(), and always forget that close parenthesis. Obviously that causes many problems.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    Writing js after php:
    (variables and almost ALWAYS forgot document.)
    Code:
    $myvalue = getElementById("thisis").value;
    Writing PHP after js:

    Code:
    <?php
    var $myvariable = $_POST['value'];
    ?>

  10. #10
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    Last year I was redesigning our schools website. I had to use asp for the server side language... After that I would go to a C# class later on in the day. Then go home and program using php...

    YOU CAN ONLY IMAGINE THE JUNK I WENT THROUGH...

Bookmarks

Posting Permissions

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