JMRKER's Profile User Rating: -----

Reputation: 133 Stalwart
Group:
Contributors
Active Posts:
866 (0.35 per day)
Joined:
25-October 08
Profile Views:
11,235
Last Active:
User is offline Jul 01 2015 10:41 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Who Cares
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
50

Latest Visitors

Icon   JMRKER has not set their status

Posts I've Made

  1. In Topic: Problem With My Script

    Posted 26 Jun 2015

    If you could have seen it, it was just the lines I would have done differently based upon your post.
  2. In Topic: Problem With My Script

    Posted 26 Jun 2015

    View Postandrewsw, on 26 June 2015 - 10:40 AM, said:

    @JMRKER Please do not post a full coded solution, this is against the accepted practice of this site.

    (When posting a full HTML page please also include a DOCTYPE declaration. We need to encourage this practice, and requirement.)



    Sorry, I guess I don't understand the purpose of the forum if not for educational purposes.
    Sort of defeats the purpose of users asking for help if submissions are just deleted.

    As I had indicated in the deleted code, I would not have coded that way but tried to at least
    give a working script from which to continue discussions using the OP's posted code (as was)
    and to allow other users to comment on alternative methods/solutions.
  3. In Topic: Help with JavaScript Function: Print out the next 20 leap years

    Posted 17 Jun 2015

    Using 'felgall's function, you can shorten it quit a bit.
    <script>
    function isLeapYear( year ) { return ( (new Date( year, 1, 29 )).getDate() === 29); }
    
    function leapYearCalc(yr) {
      var counter = 20;
      while (counter > 0) {
        if (isLeapYear(yr)) {
          counter--;
          console.log(yr); document.writeln(yr+'<br>');
        }
        yr++;
      } 
    }
    
    var year = prompt("please input a year to find out the next 20 years");
    leapYearCalc(year);
    </script>
    


    I thought you requested the next 20 leap years.

    Quote

    QUESTION: Write a function that takes ANY year given by user, and prints out the NEXT 20 leap years.

    Your code listed the leap years found in the next 20 years.
    Slightly different results.

    Note, you should keep as many variables local to the function
    as possible (ie, counter and year) to avoid possible conflicts
    with other functions you might develop in the future as your
    scripts become more complicated.

    In your code the variable 'counter' is global and 'year' is both local and global.
    Will lead to many problems in longer and more function dependent scripts.

    Good luck with your studies.
    :)
  4. In Topic: Help with JavaScript Function: Print out the next 20 leap years

    Posted 16 Jun 2015

    Another possibility...
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title> Next 20 Leap Years </title>
    </head>
    <body>
    <input type="text" id="beginYear" value="1890">
    <button onclick="list20LeapYears()">Next 20 leap years</button>
    <pre id="debug"></pre>
    
    <script type="text/javascript">
    // From: http://javascript.about.com/library/bldayyear.htm
    Date.prototype.getDOY = function() {  // returns day-of-year (0...364, [365 leap year])
      var onejan = new Date(this.getFullYear(),0,1);
      return Math.ceil((this - onejan) / 86400000);
    }
    function list20LeapYears() {
      var nd, ld, ly = [], yr = document.getElementById('beginYear').value*1;
      while (ly.length < 20) {
        nd = new Date(yr,11,31);
        ld = nd.getDOY();
        if (ld == 365) { ly.push(yr); } // found leap year when ld=365
        yr++;
      }
      document.getElementById('debug').innerHTML = ly.join('<br>')+'<hr>';
    }
    </script>
    </body>
    </html>
    
  5. In Topic: degrees based trig

    Posted 10 Jun 2015

    Not a perfect solution,
    but maybe adjustable or sufficient for your needs ...

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title> HTML5 page </title>
    </head>
    <body>
    <pre id="debug"></pre>
    
    <script type="text/javascript">
    var precision = 15;
    function tan(angleValue) {
      var tan = Math.tan((angleValue * Math.PI) / 180);
      if (Math.abs(tan) > 60000) { return 'undefined'; }  // or 'NaN' string
      return tan.toFixed(precision); 
    }
    
    /* Expectations:
    
    135 degrees shows a tan of -1.0000000000000002 (should be -1)
    
    60 degrees shows a tan of 1.7320508075688767 (should be &radic;3 or about 1.7320508075688767)
    
    90 degrees shows a tan of 16331239353195370 (should be NaN)
    
    Yes, the examples are from the comic strip FoxTrot.
    */
    
    document.getElementById('debug').innerHTML =  'Degrees to Radians<p>';
    document.getElementById('debug').innerHTML += 'tan(0) = '+tan(0)+'<p>';
    document.getElementById('debug').innerHTML += 'tan(180) = '+tan(180)+'<p>';
    document.getElementById('debug').innerHTML += 'tan(135) = '+tan(135)+'<p>';
    document.getElementById('debug').innerHTML += 'tan(45) = '+tan(45)+'<p>';
    document.getElementById('debug').innerHTML += 'tan(60) = '+tan(60)+'<p>';
    document.getElementById('debug').innerHTML += 'tan(150) = '+tan(150)+'<p>';
    document.getElementById('debug').innerHTML += 'tan(89.999) = '+tan(89.999)+'<p>';
    document.getElementById('debug').innerHTML += 'tan(90) = '+tan(90)+'<p>';
    document.getElementById('debug').innerHTML += 'tan(90.001) = '+tan(90.001)+'<p>';
    
    </script>
    </body>
    </html>
    
    

My Information

Member Title:
D.I.C Addict
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Florida
Programming Languages:
javascript, perl, java, forth, basic, fortran, assembly (several)

Contact Information

E-mail:
Private
Website URL:
Website URL  http://

Friends

Showing 50 random friends of 4

Comments

JMRKER has no profile comments yet. Why not say hello?