Hi all Javascript pros. I'm quite new with javascript and i have a function here that i don't realy understand (from a book i have). Now my question is. Could somebody please explain the code to me part by part? And maybe show other ways to write the code? It would be very nice of you. If you need my mail then just ask, then you can send it on my email if you'd like. Here's the code.. And thank you .
function sistaefternamnen() {
var temp = "";
for (var i = 1; i < 4; i++) {
if ((registrerade-i) == 0 || i == 3 && (registrerade-i) >= 0) {
temp = temp + efternamn[registrerade-i];
}
else if ((registrerade-i) > 0) {
temp = temp + efternamn[registrerade-i] + ", ";
}
else {
break;
}
}
var tempP = document.getElementById('p3');
tempP.lastChild.nodeValue = temp;
}
function sistaefternamnen() {
var temp = "";
for (var i = 1; i < 4; i++) {
if ((registrerade-i) == 0 || i == 3 && (registrerade-i) >= 0) {
temp = temp + efternamn[registrerade-i];
}
else if ((registrerade-i) > 0) {
temp = temp + efternamn[registrerade-i] + ", ";
}
else {
break;
}
}
var tempP = document.getElementById('p3');
tempP.lastChild.nodeValue = temp;
}