## JMRKER's Profile User Rating:

Reputation: 130 Stalwart
Group:
Contributors
Active Posts:
839 (0.37 per day)
Joined:
25-October 08
Profile Views:
9,795
Last Active:
Today, 08:41 AM
Currently:
Offline

### Previous Fields

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

### Latest Visitors

JMRKER has not set their status

1. #### In Topic: Need Help With Grade Calculator

Posted 2 Dec 2014

Modified letterGrade function (smaller) with example display
```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />

<title> HTML5 page </title>

<body>

<script type="text/javascript">
var grades =    [ 0, 60,  67, 70,  77, 80,  87, 90,  97];
score = parseInt(score*1);
for (var i=0; i<grades.length; i++) {
}

// 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'; }

</script>

</body>
</html>

```
2. #### 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>
<title> Computer Science Class </title>
<meta charset="utf-8">
<style>
input {width: 100%}
</style>
<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>
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; }
}

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;

}
</script>

</body>
</html>

```
3. #### In Topic: Limit text and add ellipsis global function

Posted 26 Oct 2014

I maybe going a bit crazy with this, but I've tried to make it more programmer friendly. />

The following code:
1. Can have Vertical and Horizontal displays using <ul> and <li> tags
2. May use Single or Multiple ellipse displays placed as desired using <div> tags
3. No longer uses a required correct index to saved .innerHTML text display.
4. Can have variable number of words shown before ellipse display
5. Allows different widths/colors via use of CSS element changes

As far as tested, still degrades to visible HTML if JS not enabled.

```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<title> Multiple Ellipse Horiz/Vert Displays </title>

<style type="text/css">
.msgSH { border:1px solid black; width:175px; background-color:#ffffdd; margin:3px 0px; }
#msg li { list-style-type:none; }                     /* horiz & vert display */
#msg li { display:inline-block; vertical-align:top; } /* horiz display only */
</style>

<body>
<h2>Ellipse Horizontal/Vertical Displays</h2>
<ul id="msg">

<li id="msg0" sh='show' ptr='0' class="msgSH" onclick="toggleLimit(this.id)">
Sample display #0 without ellipse ending.
</li>

<li id="msg1" sh='show' ptr='0' class="msgSH" onclick="toggleLimit(this.id)">
Sample display #1 without ellipse ending and additional text.
</li>

<li id="msg2" sh='show' ptr='0' class="msgSH" onclick="toggleLimit(this.id)">
Sample display #2 without ellipse ending.
<p>Multiple lines can be shown.
<p>Could also include links: <a href="http://www.yahoo.com">Yahoo Homepage</a>
</li>

<br>

<li id="msg3" sh='show' ptr='0' class="msgSH" onclick="toggleLimit(this.id)">
Sample display #3 without ellipse ending.
</li>

<li id="msg4" sh='show' ptr='0' class="msgSH" onclick="toggleLimit(this.id)">
Sample display #4 without ellipse ending and additional text.
</li>

</ul><p>
<div id="msgDIV" sh='show' ptr='0' class="msgSH" onclick="toggleLimit(this.id)">
Sample display (#5) of DIV without ellipse ending.
Multiple lines can be shown including links to
</div>

<script type="text/javascript">

var limitText = function (text, limit) {
var words = text.split(' ');
var newWords = [], str = '';
if (limit == 0) { newWords = words.slice(0); }  // copy ALL words
else { newWords = words.slice(0,limit); str = ' ...'; } // limit word copy
return newWords.join(' ')+str;
};

var txtLimit = [];  // Holds initial contents of displays in case JS is enabled
function toggleLimit(IDS) {
var sh = document.getElementById(IDS).sh;
var ndx = document.getElementById(IDS).ptr;
var txt = txtLimit[ndx];
if (sh == 'hide') {
document.getElementById(IDS).sh = 'show';
document.getElementById(IDS).innerHTML = limitText(txt,0);  // show ALL words
} else {
document.getElementById(IDS).sh = 'hide';
document.getElementById(IDS).innerHTML = limitText(txt,4);  // limit display to 4 words
}
}
var sel = document.getElementsByClassName('msgSH');
for (var i=0; i<sel.length; i++) {
txtLimit.push(document.getElementById(sel[i].id).innerHTML);
sel[i].ptr = i.toString();
toggleLimit(sel[i].id);
}
}
</script>

</body>
</html>

```
4. #### In Topic: Limit text and add ellipsis global function

Posted 26 Oct 2014

That last post was very interesting to me. I played with it to create MULTIPLE ellipse displays.
Pretty easy to change sizes and colors within the display as well as add other elements
if you don't plan on doing much additional processing.

```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />

<title> Multiple Ellipse Displays </title>
<style type="text/css">
.msgSH { border:1px solid red; width:175px; background-color:#fff000; }
</style>

<body>
<h2>Ellipse Displays</h2>
<div id="msg0" sh='show' class="msgSH" onclick="toggleLimit(this.id,0)">
Sample display #0 without ellipse ending.
</div><p>
<div id="msg1" sh='show' class="msgSH" onclick="toggleLimit(this.id,1)">
Sample display #1 without ellipse ending and additional text.
</div><p>
<div id="msg2" sh='show' class="msgSH" onclick="toggleLimit(this.id,2)">
Sample display #2 without ellipse ending.
<p>Multiple lines can be shown.
<p>Could also include links <a href="http://www.nova.edu/~rumsey">Homepage</a>
</div><p>

<script type="text/javascript">

var limitText = function (text, limit) {
var words = text.split(' '),
wordsStart = words.length,
newWords = words.slice(0, limit);

if (wordsStart > limit) { return newWords.join(' ') + " ..."; }
else { return newWords.join(' '); }
};

var txtLimit = [];  // Holds initial contents of displays incase JS is enabled

function toggleLimit(IDS,ndx) {
var sh = document.getElementById(IDS).sh;
var txt = txtLimit[ndx];
if (sh == 'hide') {
document.getElementById(IDS).sh = 'show';
document.getElementById(IDS).innerHTML = limitText(txt,1000);  // txt.length);
} else {
document.getElementById(IDS).sh = 'hide';
document.getElementById(IDS).innerHTML = limitText(txt,4);
}
}

var sel = document.getElementsByClassName('msgSH');
for (var i=0; i<sel.length; i++) {
txtLimit.push(document.getElementById(sel[i].id).innerHTML);
toggleLimit(sel[i].id,i);
}
}

</script>

</body>
</html>

```

I then went on to create a multiple column drop display with a bit more modifications to your code.
```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />

<title> Ellipse Horizontal Displays </title>
<style type="text/css">
.msgSH { border:1px solid black; width:175px; background-color:#ffffdd; }
#msg li { list-style-type:none; display:inline-block; vertical-align:top; }
</style>

<body>
<h2>Ellipse Horizontal Displays</h2>
<ul id="msg">
<li id="msg0" sh='show' class="msgSH" onclick="toggleLimit(this.id,0)">
Sample display #0 without ellipse ending.
</li>
<li id="msg1" sh='show' class="msgSH" onclick="toggleLimit(this.id,1)">
Sample display #1 without ellipse ending and additional text.
</li>
<li id="msg2" sh='show' class="msgSH" onclick="toggleLimit(this.id,2)">
Sample display #2 without ellipse ending.
<p>Multiple lines can be shown.
<p>Could also include links <a href="http://www.nova.edu/~rumsey">Homepage</a>
</li>
</ul>

<p>

<script type="text/javascript">

var limitText = function (text, limit) {
var words = text.split(' '),
wordsStart = words.length,
newWords = words.slice(0, limit);

if (wordsStart > limit) { return newWords.join(' ') + " ..."; }
else { return newWords.join(' '); }
};

var txtLimit = [];  // Holds initial contents of displays incase JS is enabled

function toggleLimit(IDS,ndx) {
var sh = document.getElementById(IDS).sh;
var txt = txtLimit[ndx];
if (sh == 'hide') {
document.getElementById(IDS).sh = 'show';
document.getElementById(IDS).innerHTML = limitText(txt,1000);  // txt.length);
} else {
document.getElementById(IDS).sh = 'hide';
document.getElementById(IDS).innerHTML = limitText(txt,4);
}
}

var sel = document.getElementsByClassName('msgSH');
for (var i=0; i<sel.length; i++) {
txtLimit.push(document.getElementById(sel[i].id).innerHTML);
toggleLimit(sel[i].id,i);
}
}

</script>

</body>
</html>

```

Both forms of display seem to degrade well in the case where JS is not enabled.

Thanks for the idea. />
5. #### In Topic: I need to delete min and max values from array

Posted 16 Oct 2014

One (of many) possible solution...

```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />

<title> HTML5 page </title>

<body>

<script type="text/javascript">

Array.prototype.removeMin = function() {
var p = 0,  min = this[p], arr = [];
for (var i=0; i<this.length; i++) { arr.push(this[i]);
if (this[i] < min) { p = i; min = this[i]; }
}
arr.splice(p,1);
return arr;
}
Array.prototype.removeMax = function() {
var p = 0,  max = this[p], arr = [];
for (var i=0; i<this.length; i++) { arr.push(this[i]);
if (this[i] > max) { p = i; max = this[i]; }
}
arr.splice(p,1);
return arr;
}
var origArray = [5,4,3,2,1,10,9,8,7,6];
var minRemoved = origArray.removeMin();
var maxRemoved = origArray.removeMax();

alert('orig: '+origArray+'\n\nmin removed: '+minRemoved+'\n\nmax removed: '+maxRemoved);
</script>

</body>
</html>
```

You could combine the two functions into one, if desired.

```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />

<title> HTML5 page </title>

<body>

<script type="text/javascript">

Array.prototype.removeMin = function() {
var p = 0,  min = this[p], arr = [];
for (var i=0; i<this.length; i++) { arr.push(this[i]);
if (this[i] < min) { p = i; min = this[i]; }
}
arr.splice(p,1);
return arr;
}
Array.prototype.removeMax = function() {
var p = 0,  max = this[p], arr = [];
for (var i=0; i<this.length; i++) { arr.push(this[i]);
if (this[i] > max) { p = i; max = this[i]; }
}
arr.splice(p,1);
return arr;
}
Array.prototype.MinMaxRemove = function() {
var min = this[0], max = this[0], arr = [];
for (var i=0; i<this.length; i++) { // arr.push(this[i]);
if (this[i] < min) { min = this[i]; }
if (this[i] > max) { max = this[i]; }
}
for (var i=0; i<this.length; i++) {
if (this[i] != min && this[i] != max) { arr.push(this[i]); }
}
return arr;
}

var origArray = [5,4,3,2,1,10,9,8,7,6];
var minRemoved = origArray.removeMin();
var maxRemoved = origArray.removeMax();
var minmaxOut  = origArray.MinMaxRemove();

alert('orig: '+origArray+'\n\nmin removed: '+minRemoved+'\n\nmax removed: '+maxRemoved+'\n\nUnique: '+minmaxOut);
</script>

</body>
</html>
```

### My Information

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

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