
I'm trying to write a program to count the average of 5 numbers that are entered into input fields, but it's not working as expected, what's wrong with my code?
document.getElementById returns element object which has multiple properties.
If you want to get value of input field, after selected input field you can access it's value using value property, e.g.
var num1 = document.getElementById('n1').value;
// ^^^^^^
Now your num1 variable contains the text entered into input field. Notice that I said text, not number. If you want to apply math to the values, you need to convert them to numbers, like this:
var num1 = Number(document.getElementById('n1').value);
// ^^^^^^^ ^
Only then you will get correct result. But we're not done yet, as you probably want to see that result. As I mentioned previously, document.getElementById gives you reference to the element, that has multiple properties. Another property is innerText. You can set it to the value you want to be able to see it:
document.getElementById('everresult').innerText = result;