looping through the button always give me 0 answer : <p>Here's the code. Thank you for helping me.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>/*this code works fine in code snippet and (when I run the code in the chrome console but when I write the code in my file.js, this won't work*/
var btn = document.getElementsByTagName('button');
alert(btn.length);
// it must alert 3, but I always get 0. Please help me. Thank you</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button&gt;Games&lt;/button&gt;
&lt;button&gt;Foods&lt;/button&gt;
&lt;button&gt;Movies&lt;/button&gt;</code></pre>
</div>
</div>
</p>
