// Get only the roster section
var roster = document.getElementById("roster");
// Get all the rows of the roster table
var rows = roster.getElementsByTagName("tr");
// Loop for each row, but start with the 2nd row
for (var r = 1; r < rows.length; r++) {
// Fetch the individual row (code given below)
var row = rows[r];
// Use getElementsByTagName to get all the td tags (code given below)
var cols = row.getElementsByTagName("td");
// Get the second td tag, which stores the full name (code given below)
var secondTD = cols[1];
// Get the innerHTML of the second td tag and store it as a string called fullname
var fullname = secondTD.innerHTML;
// Use the JavaScript replace method to replace apostrophes and periods with an empty character ('')
var clean = fullname.replace(/[^\w\s]/gi,'');
// Use the JavaScript toLowerCase to make sure the full name is all lower case letters
var lowcase = clean.toLowerCase();
// Use the JavaScript split function to break the string into array components
// Assume the first component is the first name
// Assume the second component is the second name
var spl = lowcase.split(" ");
var first = spl[0];
var last = spl[1];
// Use String concatentation (+) to make the URL string (last + "_" + first + ".html")
var conc = last+ "_" +first+ ".html";
// Use createElement to make a new hyperlink element
var hl = document.createElement('a');
// Use createTextNode to make a new text node for the fullname, i.e., createTextNode(fullname)
var hlnode = document.createTextNode(fullname);
// Use appendChild to append the text node inside the hyperlink element
hl.appendChild(hlnode);
// Use setAttribute to set the "href" attribut to the URL string above
hl.setAttribute("href", conc);
// Remove the text node of the second td tag (code given below)
var old = secondTD.childNodes[0];
secondTD.removeChild(old);
// Use append child to append the hyperlink element inside of the second td tag
secondTD.appendChild(hl);
//replacing text code
var thirdTD = cols[2];
var positionname = thirdTD.innerHTML;
var temp;
if (positionname == 'PG'){
var temp2 = document.createTextNode("Point Guard");
temp = thirdTD.childNodes[0];
thirdTD.removeChild(temp);
thirdTD.appendChild(temp2);
}
else if (positionname == 'SG'){
var temp2 = document.createTextNode("Shooting Guard");
temp = thirdTD.childNodes[0];
thirdTD.removeChild(temp);
thirdTD.appendChild(temp2); }
else if (positionname == 'SF'){
var temp2 = document.createTextNode("Small Forward");
temp = thirdTD.childNodes[0];
thirdTD.removeChild(temp);
thirdTD.appendChild(temp2); }
else if (positionname == 'PF'){
var temp2 = document.createTextNode("Power Forward");
temp = thirdTD.childNodes[0];
thirdTD.removeChild(temp);
thirdTD.appendChild(temp2); }
else if (positionname == 'C'){
var temp2 = document.createTextNode("Center");
temp = thirdTD.childNodes[0];
thirdTD.removeChild(temp);
thirdTD.appendChild(temp2); }
}