Codesmith Challenge: Control Flow and Iteration
Challenge: Iterate through the array and multiply a number by 10 if it is greater than or equal to 5.
Solution and Work through:
Logic:
1. iterate through the array using a loop. In this case, I’d use a “for loop”.
2. The variable (i) parsed in the loop argument should be assigned a value . This will make it iterate the array from an index of 0. The loop conditional should check if i is less than the length of the const “timesTenIfOverFive” using the .length property. lastly, increment i.
3. Using conditionals check if the constant timesTenIfOverFive at an index of [i] is greater than 5, if true multiply by 10 and assign its result to timesTenIfOverFive[i].
The graphical illustration below: