<SCRIPT language="JavaScript">
height = screen.height;
width = screen.width;
document.write( width*height + " pixels");
</SCRIPT>
I would like my answer to return with commas separating the numbers rather than one full number.
<SCRIPT language="JavaScript">
height = screen.height;
width = screen.width;
document.write( width*height + " pixels");
</SCRIPT>
I would like my answer to return with commas separating the numbers rather than one full number.
Here's a fun way to do it:
function format(num) {
return ("" + num).split("").reverse().reduce(function(acc, num, i, orig) {
return num + (i && !(i % 3) ? "," : "") + acc;
}, "");
}
format(777782374);
Prints:
"777,782,374"
Or, if you want to support decimals:
function format(num, fix) {
var p = num.toFixed(fix).split(".");
return p[0].split("").reduceRight(function(acc, num, i, orig) {
var pos = orig.length - i - 1
return num + (pos && !(pos % 3) ? "," : "") + acc;
}, "") + (p[1] ? "." + p[1] : "");
}
format(777782374, 4);
Prints:
"777,782,374.0000"
Than you shouldn't multiply them?
document.write( width + ", " + height + " pixels");