Looping manually


#1

Next, console.log() each item in vacationSpots on a separate line. To do this, list out each item using property access.
Nice work! That wasn’t too hard, but imagine if our vacation list had 100 places on it. Logging each item to the console by hand would be an extremely tedious task!
Let’s make this more efficient with a for loop.

const vacationSpots = ['France', 'Grand Canyon', 'Mexico']

for(let i=0;
    i<vacationSpots.length; i++)
  {
    
    console.log(vacationSpots[i])
  }

Heres what it outputs

France
Grand Canyon
Mexico

heres the error message:

Did you console.log vacationSpots[0]?

Why doesn’t this code pass this lesson? I’ve done what its asked??


#2

Hi @sideburnsg,

Could you provide the link to the exercise, it’s easier to see what’s the instruction given.

Thanks :slight_smile:


#3

https://www.codecademy.com/courses/learn-javascript-loops/lessons/loops/exercises/manual-loop?action=lesson_resume&course_redirect=introduction-to-javascript


#4

even the code it provides with get code fails.


#5

must be a bug in codecademies lesson validation


#6

You mean you cannot pass the exercise even with the Get Code answer?

Mind to share what’s the answer given?

What about trying logging off and log in again with different browser?

I’m using Chrome here.


#7

Yeah it fails the code but when i hit refresh it worked I’m pretty certain my code should have passed Below is the code that it provides when you hit get code which fails until i refresh the page… the javascript exercises have been really buggy :frowning: makes for a lot of confusion.

let vacationSpots = ['San Francisco', 'New Zealand', 'Baja'];

for (let vacationSpotIndex = 0; vacationSpotIndex < vacationSpots.length; vacationSpotIndex++) {
  console.log('I would love to visit ' + vacationSpots[vacationSpotIndex]);
}

#9

The author wants you to do it without a for-loop (that’s what they mean by manually)

vacationSpots[0]
vacationSpots[1]
vacationSpots[2]

They’re checking this with regex patterns which is something to look out for because that means you have to write what the author expects (correct solutions may not match the pattern they wrote)

      var checks = [
        {
          msg: 'Did you console.log vacationSpots[0]?',
          regex: /console.log\( *vacationSpots\[0\] *\)/m
        },

#10

@ionatan,

Oh no! I guess I need more shut eye time. Thanks for the note and clarification!

Exercise instruction:
Next, console.log() each item in vacationSpots on a separate line. To do this, list out each item using property access. :scream:

Nice work! That wasn’t too hard, but imagine if our vacation list had 100 places on it. Logging each item to the console by hand would be an extremely tedious task!

Let’s make this more efficient with a for loop.

Where my eyes focus on the last sentence.

Next, console.log() each item in vacationSpots on a separate line. To do this, list out each item using property access.

Nice work! That wasn’t too hard, but imagine if our vacation list had 100 places on it. Logging each item to the console by hand would be an extremely tedious task!

Let’s make this more efficient with a for loop.

And I totally miss out the Looping Manually - title of the exercise.
That’s why i don’t excel in exams…


#11

I don’t know why it would say "Let’s make this more efficient using a for loop"
If that’s not what it wants you to do maybe it’s referring to the next exercise? I’ll try logging each individual index via console.log(vacastionSpots[0]) and so on when I get home which is probably what it wants. Very misleading question when your half awake lol


#12

Very misleading instructions when at the end it says let’s try making this more efficient with a for loop. I didn’t even think to try just logging each individual index


#13

Well @sideburnsg, I would not say it’s misleading. I passed the lesson a while ago, therefore when I went back to the link just now, my answer is different because I’ve already finished those exercises, and the code that stick there is based on the very end of exercise.

I would say it’s my fault not reading it carefully, but to clarify, I was not having this problem last time, guess I was more diligent when I first learning JS through the exercises, I read those instructions without letting any line leaves my eye sight.

Like I corrected, the focus should be:

Next, console.log() each item in vacationSpots on a separate line. To do this, list out each item using property access.

Nice work! That wasn’t too hard, but imagine if our vacation list had 100 places on it. Logging each item to the console by hand would be an extremely tedious task!

Let’s make this more efficient with a for loop.

This misread did not happen during my learning time, luckily. That’s why I didn’t encounter that road block. :wink:


Add on: New users would not be confused about this lesson, as they would not know how to use a For loop before the lesson introduce them, thus will be lead to only use manual printing. So @sideburnsg, guess you might have some JS knowledge prior to that? :grinning:


#14

Well I’ve done lots in Python and have been reading a lot about jS I got a little ahead of myself I guess and didn read the instructions correctly


#15

Yeah it was definitely asking for me to log each one manually as

console.log(vacationSpots[0])
console.log(vacationSpots[1])
console.log(vacationSpots[2])

lmao i have to read the instructions more carefully


#16

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.