Unit 5 Lesson 4 (U5L4) RemindMe code

I am looking at the same code to create the Reminder List in U5 L4. I want to know what does index++ and index–; do in the code for left button and right button? Does it meant to scroll 1 less or 1 more click?

What code is for the “counter pattern with Boundary”? What does that mean?

1 Like

index++ adds 1 to the value of index and assigns it to index while evaluating to the value before adding 1. It is similar to index = index + 1; There is a difference in that if you set index to 3 say; index = 3; and then assign it to x like this x = index++ The value of x is 3 and the value of index is 4.

On the other hand ++index adds one to index and evaluates to the new value. So index = 3; and then assign it to x like this x = ++index The value of x is 4 and the value of index is also 4.

So be careful how you use x++ as an expression. It may not do what you think, ++x does what you think.

index-- is the same except subtract 1.

1 Like

Counter pattern with boundry is just the counter pattern with limits on how high or how low it can go.

So looking at this code what we see is a test to see if index > 0 and if so go ahead and decrement the counter. It will never go lower than 0. The first item in the list.

We also see a test to see if index < myList.length - 1 and then index++. That means index will never be more than the last item in the list.

Thank you for explaining this! The index++ and index-- are not introduced in the lessons before this, at least not that I’ve seen. But the example answer for this lesson recommends them for the RemindMe app. The same with the boundary pattern. Could someone add those to the units?

I will pass on your request to code.org

1 Like

@erogers Sorry I’m just responding to this. I have logged this as a change to make for the 21-22 version of the course!

Thank you, Ken! I appreciate your response.

Hello, this is only my second year of teaching CS Principles. Would someone be willing to share their code for this lesson? We are stuck in my classroom, and I’m not sure how to proceed.

Thank you in advance.

Go to Unit 5 lesson 4 bubble 3. Open the teacher panel. There is a button to get the example solution.

Well that’s helpful! Thank you!