![]() ![]() The output is all the even numbers between 10 & 30. To get only even numbers, we increment i by 2! ( i += 2). ![]() i starts from 10, and ends at 30 ( i < 31). Once you do it yourself, check the code below for a solution: Click here for the CodeĬarefully check the code. ![]() Print the numbers from 10 to 30 (including 30), thar are divisible by 2. ![]() If you do not understand any part of this, I am adding links to some of my previous blogs which go through these concepts in detail: Inside for, the code is accessing the age property of an Object inside the array individuals, and checking to see if it is greater than or equal to 18! If it is it prints it out on the console. TL DR: Whatever is inside the for loop, run it 20 times beginning from 0 (starting value of i) to 19 (ending value of i) and increment i by 1. Point 3: Since you want to check for every element in the array, you increment i by 1. The length of the array is 20! Therefore, with this stop condition we make sure that i will never be greater than 19, which is the index of the last Object in the array. Therefore, you would always want i to be less than or equal to the last position of the array. Point 2: You want to run the loop for all the individuals in the array. To do that, you initialize a new variable i with the value 0. We need to run the if code block for every element in the array from index 0 to index 19 (length is 20). Length of the array can be accessed by array.length.You index an element with square brackets, for example: individuals will return the details for Aaron.The position of the first element is denoted by 0. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |