Passed the Lesson, but Code not Printing Desired Values


Hi there. So I'm in the Review section of the Lesson 7 (where you use all the loops learned thus far) and I passed...but the code I wanted to run isn't running as intended. I want to figure out why before I move on. My code is:

var point = 1
for(var i = 0; i < 27; i+=3){
    console.log("Counting your points...")}
while(point > 20){
    console.log("Your points are " + point[i])}

I want the code to count each point you get before the for loop ends, and print them out as "Your points are...". It works, but apparently points is undefined when it prints out the end result. Where did I go wrong, and why?


You're treating point both like a number and like a collection of numbers (like an array), which is it?

Tip on asking questions: avoid "working"/"not working" in general - your question is very well explained but the title almost made me skip the topic, more like "unable to print values, getting undefined".. It's not easy, just sharing my view. Also, marking your code as code in your post (putting ``` before and after the code on their own lines) as well as putting brackets and such where they belong makes for a really pretty post :slightly_smiling: like this:

var point = 1;
for (var i = 0; i < 27; i+=3) {
do {
    console.log("Counting your points...");
while (point > 20) {
    console.log("Your points are " + point[i]);

And keeping a nice consistent format while coding helps to read it in a more "visual" way, some mistakes become easier to spot and common patterns are immediately recognized, which is also why it helps posting it like this in your question.


Thanks for the tips. So should I take the aspect of my code out that's treating point as an array?


If it's meant to just be a single number, yeah. Or perhaps it should be an array. It just can't be both.

Oh oops. Formatting got me too. I meant triple back-ticks: ``` alternatively add 4 spaces in front of each line (I think that's what the post editor does when you click the "mark as code" button thingy


Oh and I just spotted something else.. That "do-while" loop lacks a condition. Or perhaps the "while" loop does, I can't tell haha.