From 39c0568d41e8b270224ccce0bf0e70a18a08300a Mon Sep 17 00:00:00 2001 From: Flex Zhong Date: Sun, 5 Sep 2021 11:36:49 +0800 Subject: [PATCH] Update README.md --- 2-js-basics/4-arrays-loops/README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/2-js-basics/4-arrays-loops/README.md b/2-js-basics/4-arrays-loops/README.md index e3e0e503..35f314f9 100644 --- a/2-js-basics/4-arrays-loops/README.md +++ b/2-js-basics/4-arrays-loops/README.md @@ -21,11 +21,15 @@ Working with data is a common task for any language, and it's a much easier task The syntax for an array is a pair of square brackets. -`let myArray = [];` +```javascript +let myArray = []; +``` This is an empty array, but arrays can be declared already populated with data. Multiple values in an array are separated by a comma. -`let iceCreamFlavors = ["Chocolate", "Strawberry", "Vanilla", "Pistachio", "Rocky Road"];` +```javascript +let iceCreamFlavors = ["Chocolate", "Strawberry", "Vanilla", "Pistachio", "Rocky Road"]; +``` The array values are assigned a unique value called the **index**, a whole number that is assigned based on its distance from the beginning of the array. In the example above, the string value "Chocolate" has an index of 0, and the index of "Rocky Road" is 4. Use the index with square brackets to retrieve, change, or insert array values. @@ -71,10 +75,10 @@ The `for` loop requires 3 parts to iterate: - `iteration-expression` Runs at the end of each iteration, typically used to change the counter value ```javascript - //Counting up to 10 - for (let i = 0; i < 10; i++) { - console.log(i); - } +// Counting up to 10 +for (let i = 0; i < 10; i++) { + console.log(i); +} ``` ✅ Run this code in a browser console. What happens when you make small changes to the counter, condition, or iteration expression? Can you make it run backwards, creating a countdown?