From 883729a44e22fb67d110db75f1be0a78b3e63d84 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Sun, 4 Nov 2018 11:04:50 -0600 Subject: [PATCH 1/4] Initial Commit --- 04week/loop.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/04week/loop.js b/04week/loop.js index e69de29bb..eb109abbe 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -0,0 +1,2 @@ +'use strict'; + From 8296955a1e67688edbd04ca67fec9d6deadd16d2 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Sun, 4 Nov 2018 15:48:12 -0600 Subject: [PATCH 2/4] Done? --- 04week/loop.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/04week/loop.js b/04week/loop.js index eb109abbe..4646a6220 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -1,2 +1,65 @@ 'use strict'; +const cars = ["honda","ford","fonda","hoard","horse"]; + +const carsInReverse = (arr1) => { + arr1.reverse().forEach(car => { + console.log(car) + }); +} + +carsInReverse(cars); + +cars.forEach(car => { + console.log(car) +}); + +const persons = { + firstName: "Jane", + lastName: "Doe", + birthDate: "Jan 5, 1925", + gender: "female", +} + +const printPersonalDataKeys = (obj1) => { + for (const personalData in obj1){ + console.log(personalData); + } +} + +printPersonalDataKeys(persons); + +const printPersonBirthday = (obj1) => { + for (const personalData in obj1){ + if(personalData=="birthDate") return console.log(obj1[personalData]); + } +} + +printPersonBirthday(persons); + +const countForLoop = ()=>{ + for(let i = 1; i<1001;i++){ + console.log(i) + } +} + +const countWhileLoop = () => { + let counter = 1; + while(counter<1001){ + console.log(counter); + counter++; + } +} + +const countDoWhileLoop = () => { + let counter = 1; + do { + console.log(counter); + counter++; + } while (counter<1001) +} + + +countForLoop(); +countWhileLoop(); +countDoWhileLoop(); \ No newline at end of file From 2761a2821dee5e6d0d562ba66fd2568bda428e52 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Thu, 29 Nov 2018 19:36:01 -0600 Subject: [PATCH 3/4] updates --- 04week/loop.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/04week/loop.js b/04week/loop.js index 4646a6220..87f226853 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -59,6 +59,10 @@ const countDoWhileLoop = () => { } while (counter<1001) } +// When is a for loop better than a while loop? +// How is the readability of the code affected? +// What is the difference between a for loop and a for...in loop? +// What is the difference between a while loop and a do...while loop? countForLoop(); countWhileLoop(); From 2904dc3d2338baef90baa722edeb36511b5ea150 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Thu, 29 Nov 2018 19:36:21 -0600 Subject: [PATCH 4/4] stuff changed --- 04week/loop.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/04week/loop.js b/04week/loop.js index 87f226853..9c3fdf907 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -60,9 +60,18 @@ const countDoWhileLoop = () => { } // When is a for loop better than a while loop? +// for loops are good for a known number of iterations for loops are generally better + // How is the readability of the code affected? +// + // What is the difference between a for loop and a for...in loop? +// A for loop is a general case counting loops where as for in is a loop specifically for objects + + // What is the difference between a while loop and a do...while loop? +// a while loop runs as long as a condution is true, a while loop will run at least once, and while the condition is true + countForLoop(); countWhileLoop();