Functions Rest Parameters

Can anyone help me correct what I am missing in order to output the result on web browser using ID.

<p id="demo5"></p>

<script>
function sum(...theArgs) {
  return theArgs.reduce((previous, current) => {
    return previous + current;
  });
}

console.log(sum(1, 2, 3)); // this works 
console.log(sum(1, 2, 3, 4)); // this works 
document.write(sum(1,2,3,4))// this works on console log 

 document.getElementById("demo5").innerHTML = what should I put here? Do I need to define something up in there?

You can put the return value in a variable, or just use the return value.

const total = sum(1, 2, 3);
document.getElementById("demo5").innerHTML = total;
// Or
document.getElementById("demo5").innerHTML = sum(1, 2, 3);
1 Like

Thank you for responding to my post. innerHTML = sum(1,2,3) works and it outputs its total on web browser. But const total = sum (1,2,3) just outputs the number in order.