I want to be able to pass this function either a number to return as a factorial or a number and an id for an existing element on the page, so that it can return the number as text inside my specified element. Here is my code:
function factorial(num,id){
var f=1
for (var i=2; i<=num; i++) {
f*=i;
}
if (!id) {
return f;
}
else if (id)
var msg= document.getElementById(id);
return {
msg.textContent = num + "! = " + output;
};
}
}
factorial(5,"message");
output? Should bef, isn't it?return num + "! = " + output;where doesoutputcome from ?