function Daily2() { //display total pages for the year totalpages = 0; for (j=1; j<365; ++j) { totalpages += pat[j]; } } Daily2 (); /*display the results of 'function Daily2' in a sentence*/ switch(totalpages.length) { //open a switch case "4" : //4 digit numbers document.write(totalpages.charAt(0) + "," + totalpages.substring(1,3)); break; case "5" : //5 digit numbers document.write(totalpages.substring(0,1) + "," + totalpages.substring(2,4)); break; case "6" : //6 digit numbers document.write(totalpages.substring(0,2) + "," + totalpages.substring(3,5)); break; default : //small numbers document.write(totalpages); }// close the switch