I am trying to list all numbers below a certain number provided in the textfield (see input) that is multiples of 3 or 5 and then add the multiples and outputting the sum (in this case changing the div#answers text to the sum.
Example: if that certain number is 10, then the multiple of 3 and 5 that is < 10, would be 3,5,6,9 and the sum of 3,5,6,9 is 23. I got all down as far as the solution goes but for the life of me can't output the answer.
<html>
<head>
<script>
function myFunc() {
var result = [];
var sum;
for(var i = 1; i < document.getElementById('number').value; i++) {
if(3*i < document.getElementById('number').value) {
result[i] = 3*i;
}
if(5*i < document.getElementById('number').value) {
result[i] = 5*i;
}
}
for(i = 0; i < result.length; i++) {
sum += result[i];
}
}
document.getElementById("answers").innerHTML = sum;
</script>
</head>
<body>
<input type="text" id="number" />
<input type="button" onclick="myFunc()" value="Click for answer">
<div id="answers"></div>
</div>
</body>
document.getElementById("answers").innerHTML = sum;inside the function perhaps?