![](https://i.imgur.com/56C2ubQ.png =200x) # Coaching - JavaScript 4 with Founders and Coders --- ## Recap: For loops ---- For loops will run until a condition is met, usually we set up the condition so the loop runs a fixed number of times. ---- ```javascript= let myArray = [1,2,3,4]; for (let i = 0; i < myArray.length; i++){ myArray[i]++; }; console.log(myArray) // What does i++ do? // What is the output of line 7? ``` --- ## Recap: While loops ---- While loops allow us to run a block of code until a condition is met. ---- ```javascript= let myNum = 0; while (myNum < 10){ console.log(myNum); myNum++ } ``` ---- While loops depend on us ensuring the condition is negated somewhere in our code, otherwise the loop will run forever. ---- ```javascript= let myNum = 0; while (myNum < 10){ console.log(myNum); } // This loop will run infinitely. ``` --- ## ParseInt ---- parseInt allows us to convert a string to an integer (a whole number). ---- parseInt can accept two parameters: 1. a number 2. a radix ---- ```javascript= let myNumber = 10; let myString = '10'; console.log(typeof myNumber); console.log(typeof myString); ``` ---- ```javascript= let myNumber = 10; let myString = '10'; console.log(typeof myNumber); console.log(typeof parseInt(myString, 10)); ``` ---- The _radix_ refers to the base of the number system we're using. Binary uses 2; denary uses 10; and hexadecimal uses 16. ---- In general, we will be working with base 10 numbers (denary) and so we can use 10 as our radix. --- ### toString method ---- We'll cover methods in more detail in coming weeks. ---- Adding .toString() to a variable name will convert it to a string. ---- ```javascript= let myNum = 12; console.log(typeof myNum) myNum = myNum.toString() // What is happening here? console.log(typeof myNum) ``` --- Codewars --- Next week: - Join your study group - Work on kata and share them on Discord - Work on the Discord daily challenges --- ## Ternary Operator ---- We've already seen other operators: ``` = > === -- && ``` ---- The ternarary operator is the conditional operator. ---- The conditional operator assigns a value to a variable based on a condition. ---- ![](https://i.imgur.com/5kcO3Fy.png) ---- ```javascript= let apples = 2; let oranges = 3; let pineapples = 1; function fiveADay(fruit){ let enoughFruit = (fruit > 5) ? "Yes!" : "No!"; console.log(enoughFruit); } fiveADay(apples); ``` --- ## Practice! :tada:
{"metaMigratedAt":"2023-06-16T04:49:56.720Z","metaMigratedFrom":"YAML","title":"Coaching - JavaScript 4","breaks":true,"slideOptions":"{\"theme\":\"white\"}","contributors":"[{\"id\":\"2967aacf-1990-431e-b963-91e79ce4a2bf\",\"add\":2564,\"del\":0}]"}
    225 views
   Owned this note