I am attempting to set up a very basic webpage which essentially documents various coding challenges I have completed.
I am currently attempting to take a value out of JavaScript and place it into an input box in HTML. I understand the usage of innerHTML and getElementById (and I have used both of them before to input a value into a text box) but it seems that I am missing something this time around. I can't seem to get the new value of "sum" to show in the text box.
What am I doing that is incorrect? Is the value of "sum" getting lost in the for / if statement? I apologize if this is overly simple. I cannot find anything that makes this work.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var sum = 0;
for (i = 0; i < 1000; i++) {
if (i % 3 === 0 || i % 5 === 0) {
sum = sum += i;
}
}
var totalSum = sum;
getElementById("answer1").innerHTML = totalSum;
</script>
<h1>Challenge 1</h2>
<p>Find the sum of all the multiples of 3 or 5 below 1000 (begin with 10, then work up).</p>
<p>Answer is
<input type="text" id="answer1"></input>
</p>
</body>
</html>