Why isn't this javascript code working?
Posted
by
DarkLightA
on Stack Overflow
See other posts from Stack Overflow
or by DarkLightA
Published on 2010-12-30T12:35:48Z
Indexed on
2010/12/30
12:54 UTC
Read the original article
Hit count: 336
JavaScript
I want the function to make the arguments into a single string and return it. What have I done incorrectly?
function cooncc(divider, lastdiv){
var returner;
for (var i = 0; i < (arguments.length - 2); i++)
{
returner += arguments[i+2] + divider;
}
returner -= divider;
returner += lastdiv + arguments[arguments.length - 1];
return divider;
}
var output = cooncc(", ", ", and ", "Andy", "Becky", "Caitlin", "Dave", "Erica", "Fergus", "Gaby");
document.body.innerHTML = "<h1>" + output + ".</h1>";
© Stack Overflow or respective owner