As @rcodeman already mentioned the problem is that your array is out of boundaries. You start at 5 which is not an array index any more and you stop before 0 so you cut off "Maggie" (the first array index). And according to your second example you already fixed this.
So my question is rather: Why would you use a while loop when a for loop is much nicer in this situation:
for(var count = 0;count < array.length;count++)
for(var count = array.length-1;count >=0;count--)
Each one displays all the needed information in just one line instead of spreading them over the whole course of the loop. Don't get me wrong I'm not advocating against while loops but if you want to practice them it would make sense to practice them in situations where the use actually makes sense. For example while loops are awesome because they just have a condition, so in cases where you simply do not know when this loop might stop (for example dealing with randomness or user interaction) while loops are the feature of choice. When you clearly know a start and end condition before a loop starts then for loops can wrap up all the information in a pretty one-liner. And although do/while loops might seem hard to grasp at the beginning their purpose is crystal clear -> run the code once and the go on or enter a regular while loop.
So as an example of how a while loop approach to this problem might look like have a look at this:
var nameArray = ["Maggie", "Tom", "Ritchie", "Emma", "Rupert"];
var count = 0;
Here we use the fact that
undefined has a falsy value, so the loop will stop when you exceed the boundary. And about this:
here I make use of the fact that
variable++ has, as a statement, a value of variable and afterwards increases variable by 1. You can of course use variable here as well and then use variable++ on the next line, but then you might see an additional number in the output because as said the variable++ has a value and the last value is echoed when the program ends.
This is probably a little to complicated at this point and makes use of things that are not really covered in this course, so just take it as an idea of when to use a while loop. Yours works fine it's just that for counting backwards you already need to know the length and if you know the length a for loop is better.
Hope this helps and is not too confusing
PS: It might not seem to be that different from your approach, but the lack of a
.length also means that you could modify the length of that array on the fly and this loop would still work. (of course taken into account that the modification takes places at a point after the current index.)