Getting nth child count from a div class using javascript

I am trying to find count or nth child from here. As per below I should get 3 and dynamically it will change based on number results.

<div class="result-container list-layout-container">
   <div class="list-layout">Result1</div>
   <div class="list-layout">Result2</div>
   <div class="list-layout">Result3</div>
</div>

so, I used the below function to get the length 3 but I am not getting it instead I am getting undefined or 0.
Please suggest.

var len = document.getElementsByClassName('result-container').length;
console.log("Length count is", len);