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

Reputation: 130 Stalwart
Group:
Contributors
Active Posts:
844 (0.37 per day)
Joined:
25-October 08
Profile Views:
9,963
Last Active:
User is offline Yesterday, 05:55 PM
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: Random Array element picker Java Script

    Posted 12 Jan 2015

    Original code was a "Random Array Element Picker" rather than an "Array Shuffler".

    Here is a modification to the code to demonstrate the difference...
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <title> Random Pick/Shifter </title>
    
    </head>
    <body>
    <pre id="debug"></pre>
    
    <script>
    var ar = ["HELLO", "GOODBYE", "THANK YOU", "GOOD DAY", 'HOLA', 'ADIOS', 'POR FAVOR', 'GRACIAS'];
    function rndPick(h) { 
      var num = Math.floor(Math.random() * h.length);
      return h[num];
    } 
    document.getElementById('debug').innerHTML = 'Array:<br>'+ar.join(', ');
    var t = rndPick(ar); 
    document.getElementById('debug').innerHTML += '<p>Random pick: <br>'+t;
    
    function shuffle(array) {
      var tmp, current, top = array.length;
      if(top) while(--top) {
        current = Math.floor(Math.random() * (top + 1));
        tmp = array[current];
        array[current] = array[top];
        array[top] = tmp;
      }
      return array;
    }
    ar = shuffle(ar);
    document.getElementById('debug').innerHTML += '<p>Array shuffled:<br>'+ar.join(', ');
    
    arr = ar.slice(0);
    t = '';  
    while (arr.length > 0) { t += arr.shift()+'<br>'; }
    document.getElementById('debug').innerHTML += '<p>Shifted array selections:<br>'+t;
    
    document.getElementById('debug').innerHTML 
      += '<p>Shifted array contents if array not saved:<br>'+arr+'<p>arr length: '+arr.length;
    
    
    </script>
    
    </body>
    </html>
    
    
  2. In Topic: Table building without document.write()

    Posted 8 Jan 2015

    Here is some example code that uses a "goofy" array of information
    to create two tables without using the document.write() functions.

    Might be able to modify the script for your particular "events" information.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <!--
      Data from: http://www.javascriptsource.com/miscellaneous/smarttables.html 
      TBA: smarttables sorted display
    -->
    <title> toTable Examples </title>
    
    <style type="text/css">
     #tableDIV th { background-color:#ffff00; }
     #tableStrDIV { border:1px solid blue; width:25%; }
     #tableStrDIV th { border-bottom:1px solid black; }
    </style>
    </head>
    <body>
    
    <div id="tableDIV"></div> <p>
    <div id="tableStrDIV"></div>
    
    <script type="text/javascript">
    var tblArray = [  // sample: array of arrays format
       ['','Name','Height','Weight','Lovability','Noise'],
       ['Cow','Daisy','180 cm','500 kg','15%','Moo'],
       ['Sheep','Fluffy','120 cm','40 kg','10%','Baa'],
       ['Pig','Oinky','100 cm','35 kg','40%','Oink'],
       ['Dog','Barky','056 cm','5 kg','90%','Woof'],
       ['Cat','Mewy','040 cm','3 kg','65%','Meow'],
       ['Chicken','Pecky','030 cm','2 kg','5%','Cluck'],
       ['Horse','Flicka','200 cm','400 kg','50%','Nay'],
    ];
    var tblStrArray = [  // sample: array of strings format
       'Animal,Name,Lovability,Noise',
       'Cow,Daisy,15%,Moo',
       'Sheep,Fluffy,10%,Baa',
       'Pig,Oinky,40%,Oink',
       'Dog,Barky,90%,Woof',
       'Cat,Kitty,65%,Meow',
       'Chicken,Pecky,5%,Cluck',
       'Horse,Flicka,50%,Nay',
    ];
    Array.prototype.toTable = function(bdr, wide) {
      var str = '<table border="'+bdr+'" width="'+wide+'">';
      var trec = this.shift();
          str += '<thead><tr><th>'+trec.join('</th><th>')+'</th></tr></thead><tbody>';
      for (var r=0; r<this.length; r++) {
          str += '<tr><td>'+this[r].join('</td><td>')+'</td></tr>';
      }   str += '</tbody></table>';
      return str;
    }
    Array.prototype.toStrTable = function(bdr, wide) {
      var tarr = [];
      for (var r=0; r<this.length; r++) { tarr.push(this[r].split(',')); }
      return tarr.toTable(bdr,wide);
    }
    
    window.onload = function() {
      document.getElementById('tableDIV').innerHTML = tblArray.toTable('1',"50%");
      document.getElementById('tableStrDIV').innerHTML = tblStrArray.toStrTable('0',"100%");
    }
    </script>
    
    </body>
    </html>
    
    
    
  3. In Topic: Table building without document.write()

    Posted 8 Jan 2015

    Can you provide a small example of the ics events file contents? Format and/or contents?

    Are you trying to call the events.forEach function more than once?
    Where in you program do you call this event to create the display?
  4. In Topic: Need Help With Grade Calculator

    Posted 2 Dec 2014

    Modified letterGrade function (smaller) with example display
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <title> HTML5 page </title>
    
    </head>
    <body>
    
    <script type="text/javascript">
    function letterGrade(score) {
      var grade = -1;
      var gradeChar = ['F','D','D+','C','C+','B','B+','A','A+'];
      var grades =    [ 0, 60,  67, 70,  77, 80,  87, 90,  97];
      score = parseInt(score*1);
      for (var i=0; i<grades.length; i++) {
        if (score >= grades[i]) { grade++; }
      } return gradeChar[grade];
    }
    
    // example scores and reports
    // var testScores = [0,60,67,70,77,80,87,90,97,100];                      // test for exact score changes
    var testScores = [];  for (var i=55; i<101; i++) { testScores.push(i); }  // test for range of scores
    var str = '';
    for (var i=0; i<testScores.length; i++) { str += 'Score: '+testScores[i]+' = '+letterGrade(testScores[i])+'\n'; }
    alert(str);
    
    </script>
    
    </body>
    </html>
    
    
    
  5. In Topic: Need Help With Grade Calculator

    Posted 2 Dec 2014

    While it is not the way I would do it,
    here's a fix for your logic.

    If you weight each score, then there is no reason to average the weights.
    (Unless, of course, that is what you are trying to do with your logic!).

    <!DOCTYPE html>
    <html>
    <head>
    <title> Computer Science Class </title>
    	<meta charset="utf-8">
    <style>
     input {width: 100%}
    </style>
    </head>
    <body>
    <table id="table1">
     <tr>
      <th> </th>
      <th> Score </th> 
     </tr>
     <tr>
      <td> Test 1 </td>
      <td> <input type="text" id="test1" size="20" value=""> </td>
     </tr>
     <tr>
      <td> Test 2 </td>
      <td> <input type="text" id="test2" size="20" value=""> </td>
     </tr>
     <tr>
      <td> Final Exam </td>
      <td> <input type="text" id="finalexam" size="20" value=""> </td>
     </tr>
     <tr>
      <td> Labs </td>
      <td> <input type="text" id="labs" size="20" value=""> </td>
     </tr>
     <tr>
      <td> Project </td>
      <td> <input type="text" id="project" size="20" value=""> </td>
     </tr>
     <tr>
     <td> Quizzes </td>
      <td> <input type="text" id="quizzes" size="20" value=""> </td>
     </tr>
     <tr>
      <td colspan="2"> <input type="button" value="Calculate Grade" id="clickit" onclick="multiplyit()"> </td>
     </tr>
     <tr>
      <td> <input type="text" id="total" value=""> </td>
      <td> <input type="text" id="letter" value=""> </td>
     </tr>
    </table>
    
    <script>
    function letterGrade(score) {
      var grade;
      var gradeChar = ['F','D','D+','C','C+','B','B+','A','A+'];
      score = parseInt(score*1);
      if (score < 60) { grade = 0; }
      if (score >= 60) { grade = 1; }
      if (score >= 67) { grade = 2; }
      if (score >= 70) { grade = 3; }
      if (score >= 77) { grade = 4; }
      if (score >= 80) { grade = 5; }
      if (score >= 87) { grade = 6; }
      if (score >= 90) { grade = 7; }
      if (score >= 97) { grade = 8; }  // alert(gradeChar[grade]);
      return gradeChar[grade];
    }
    
    function multiplyit() { 
     var test1=parseFloat(document.getElementById("test1").value*0.15);
     var test2=parseFloat(document.getElementById("test2").value*0.15);
     var finalexam=parseFloat(document.getElementById("finalexam").value*0.20);
     var labs=parseFloat(document.getElementById("labs").value*0.30);
     var project=parseFloat(document.getElementById("project").value*0.05);
     var quizzes=parseFloat(document.getElementById("quizzes").value*0.15);
    
     var totalPoints= (test1 + test2 + finalexam + labs + project + quizzes);
     document.getElementById("total").value=totalPoints;
    
     document.getElementById('letter').value = letterGrade(totalPoints);
    
     }
    </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://

Comments

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