How do I output the value of a variable from js in the div?

I have a function which considers the points I want to bring these points into the block on the page :
window.onload = function() {

scoreView();

 function scoreView() {
 return document.getElementById('scoreView').innerHTML = score;
};

}

The default score = 0 . This zero and displayed, but when the variable value changes, this 0 is not changed and remains the same .
June 5th 19 at 21:53
2 answers
June 5th 19 at 21:55
Solution
Do not have to use a window.onload = function().
When you connect the script to the HTML, set the defer attribute

<script src="js/script.js" defer></code><br><br><pre><code class="javascript">var score = 100; var text = document.getElementById('scoreView'); function scoreView() { text.innerHTML = score; }; scoreView();</code></pre><br><br> And in your case not necessary to use return in order to print the text.</script>
already thought of myself, I realized the stupid mistake, thanks! - Garland commented on June 5th 19 at 21:58
June 5th 19 at 21:57
https://learn.javascript.ru - You here from the beginning... the answer to the question will not change the situation in General

Find more questions by tags JavaScript