Unit 5 Lesson 4 Help

Hello all,

We are currently on Unit 5 Lesson 4 and I am looking at the example solution and see under the button functions, code that reads index++ and index–. Can anybody explain this to me? The app won’t run without it and has to be typed in as opposed to blocks as far as I can tell?

Thank you in advance!

Index is the location in the array you are at. In line #1, you are creating an array reminderList. The RIGHT BUTTON onEvent starts at 0 in that array and progress up through the list you entered, as long as it is less than the length of the list. index ++ is the same as saying index = index + 1 All it does is progress UP the list every time you hit the RIGHT BUTTON. LEFT BUTTON does the opposite. It starts at the END of the list and goes down. Index - - is the same as index = index - 1

Both of these are need to move up and down your indexs (spots) on yours list.

They both usually have to be typed in as there is not index++/index- - block

index++ and index – are shortcuts for index = index + 1 and index = index -1. Basically, those statements are just incrementing and decrementing the value of index by 1.

Hello @sruiz,

While I agree with @jeff.rhodes & @bhatnagars about the incrementor, there is a bit more i think you should know about, ++ and – can’t be used for increasing or decreasing any value by 1, additionally if your setting it to a variable
EX:

var a = 0;
var b = a++; // b will be 0
var c = a; // c will be 1

this example also applies to – as well if you want to increment it more i suggest using += & -= to get the desired result, additionally you can also put these incrementors behind variables to solve this issue if you want it to be set to the proper value I’ll use – this time in this example

var a = 10;
var b = --a; // b is 9 & a is also 9
var c = a;  // c is now 9
1 Like

Generally speaking ++i does what you think it does. i++ is a bit weird. Unfortunately, i++ is used more often.

Thank you all for your answers! The Index++ is definitely cleared up now. It’s interesting that it explains it in the following lesson

Thank you again!