I got the correct code but it won't let me pass

HI guys, I’ve created the code correctly and run it correctly but my question is: why i have to build a selection to be able to select it ?? why i can not just action this function with "comicStrip[3]??

I thought that option is the one that select and take off from the list already a listed items

1 Like

You are close but it says in the instructions that you need to save it to a variable called “Selection.” Conceptually, you are correct. You have the right index number you just need to declare a variable first.
selection = comicStrip[3]

5 Likes

maybe you forgot a capital letter? That happened to me at least, took me some time to realise, that there’s a capital letter in the middle of the list function ^^

1 Like

// Build a list
var comicStrip = [‘Codey sees the trail’, ‘Codey starts the hike’, ‘Codey is halfway’, ‘Codey reaches the finish’]

// select the 4th item from the list
comicStrip [3]

// and save it to the variable selection
selection = comicStrip [3]

10 Likes

I’m lost too! Theoretically, I get why lists are important but I’m not understanding why what I’m applying in the last exercise isn’t working. I selected solution to see the correct answer but it’s not showing me anything. When I went back to start from the beginning it’s not opening the editor this time. This is what I typed:

myList = [comicStrip]
comicStrip = [‘Codey sees the trail’, ‘Codey starts the hike,’ ‘Codey is halfway,’ ‘Codey reaches the finish’]

Is this correct?

If you reverse the order it will be. As it stands you are referencing a variable in the first line that is not yet defined.

Bear in mind that the variable reference is just that, a reference to the list literal. It is not a copy. Any changes in the list will be reflected in the referenced value.

1 Like

Okay, I think I understand. So it should look like this?:

comicStrip = [‘Codey sees the trail’, ‘Codey starts the hike,’ ‘Codey is halfway,’ ‘Codey reaches the finish’]
myList = [comicStrip]

1 Like

That will work. Did you try,

console.log(myList)

?

Note that myList cannot be iterated since it has only one element. What this basically demonstrates is that the main list is the important one. If you do not have a real reason to create the second list, then don’t. Stick with the first so it behaves like a list (array).

comicStrip.forEach(x => console.log(x))

That’s more advanced and will come up in the module on iterators. We will have covered loops in general by this point, one suspects,

for (let x of comicStrip) {
    console.log(x)
}

or if of hasn’t been learned yet,

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

No, I haven’t tried a console.log(myList). Good to know! Thanks for sharing all this info with me. I’m really new to programming so I greatly appreciate it. :grinning:

1 Like

Help me please. Here is my code:
// Build a list
comicStrip = [Codey sees the trail, Codey starts the hike,Codey is halfway, Codey reaches the finish]
// select the 4th item from the list
comicStrip[3]
// and save it to the variable selection
selection = comicStrip[3]

I have inactive Next button. What`s my mistake? Picture #3 is chosen by the code. Idk what is going on ;D

It looks like you might be using back-ticks instead of standard quote characters. Python doesn’t recognize back-ticks.

This line,

can be removed. You have it in the assignment on the next line.

1 Like

Something like this?

// Build a list
comicStrip = [`Codey sees the trail`, `Codey starts the hike`, `Codey is halfway`, `Codey reaches the finish`]
// select the 4th item from the list
comicStrip[3]
// and save it to the variable selection
selection = comicStrip[3]

It does not work yet :c

I detected that comicStrip[3] doesnn work. But i have no ideas whats the problem.

1 Like

As suspected,

`Codey sees the trail`

The strings should be written in standard quotes.

'Codey sees the trail'

And that stray line still needs to be removed.

It has no meaning and is doing nothing in the code.

I try both quotes. There is no effect.
cosmicStrip [3]…remove it, try to run. The picture is chosen, but the ‘Next’ button is inactive. Is that a bug?

It works! Thank you. I should have only update the page in browser. Always forget the simplest way. Just reset.

1 Like

this is what i came up with and it worked. my first mistake was not entering the code onder the isntructions like the first piece of code goes under ‘// Build a list’ the other code goes under ‘//select the 4th item from the list’ and so on… you get the picture… for me that was keeping me back from running the code…

// Build a list
comicStrip = [‘Codey sees the trail’, ‘Codey starts the hike’, ‘Codey is halfway’, ‘Codey reaches the finish’]

// select the 4th item from the list
comicStrip[3]
// and save it to the variable selection
selection = comicStrip[3]

It should look like this…

// select the 4th item from the list
// and save it to the variable `selection`

selection = comicStrip[3]
3 Likes

I was having the same issue as a number of other people here. I realize the problem I was having is that I was trying to be too smart and was deleting the comments. If you leave the comments that are there and type your code after the relevant comments, you won’t have any issues. (Though it would be ideal if that didn’t cause an error.)

I’m having the same issue!

I’m completely lost, I’ve typed this so far, but all i’m getting is the title Cody Goes on a Hike at the top of the RH screen? Should I be seeing an animation? I’ve coded the same as the above, but no clue how to complete it?