From 38c8153448f0b26e5f443ef8eabba0cc924e1dea Mon Sep 17 00:00:00 2001 From: deytonk Date: Thu, 26 Oct 2017 20:38:13 -0500 Subject: [PATCH 1/7] bullet point 1 --- 04week/loop.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 04week/loop.js diff --git a/04week/loop.js b/04week/loop.js new file mode 100644 index 000000000..2373dd92d --- /dev/null +++ b/04week/loop.js @@ -0,0 +1,7 @@ +'use strict'; + +const carsInReverse = ["mercedes", "bmw", "corvette", "ferrari"]; + +for (i = 0; i < carsInReverse.length; i++) { + console.log(carsInReverse[i]); +} From 58ffcaf9c508ba34e2c5f6663ac8fdc1da5bc13a Mon Sep 17 00:00:00 2001 From: deytonk Date: Sun, 29 Oct 2017 14:14:54 -0500 Subject: [PATCH 2/7] organized and first attempt at for in loop :beer: --- 04week/loop.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/04week/loop.js b/04week/loop.js index 2373dd92d..9b8009d19 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -1,7 +1,48 @@ 'use strict'; +// for loop: +// 1. Use a for loop to console.log each item in the array carsInReverse. +// for...in loop: +// 2. Create an object (an array with keys and values) called persons with the following data: +// firstName: "Jane" +// lastName: "Doe" +// birthDate: "Jan 5, 1925" +// gender: "female" +// 3. Use a for...in loop to console.log each key. +// 4. Then use a for...in loop and if state to console.log the value associated with the key birthDate. +// while loop: +// 5. Use a for loop to console.log the numbers 1 to 1000. +// do...while loop: +// 6. Use a do...while loop to console.log the numbers from 1 to 1000. + + +// 1. const carsInReverse = ["mercedes", "bmw", "corvette", "ferrari"]; for (i = 0; i < carsInReverse.length; i++) { console.log(carsInReverse[i]); } + +// 2. +const persons = { + firstName: "Jane", + lastName: "Doe", + birthDate: "Jan 5, 1925", + gender: "female" +}; + +// 3. +for (const keys in persons) { + console.log(Object.keys(persons)); +} + +// 4. +for (const values in persons) { + +} + +// 1. When is a for loop better than a while loop? + +// 2. How is the readability of the code affected? +// 3. What is the difference between a for loop and a for...in loop? +// 4. What is the difference between a while loop and a do...while loop? From f8b7c1949d31afaca31d70b3caef03d501a0eaab Mon Sep 17 00:00:00 2001 From: deytonk Date: Tue, 31 Oct 2017 12:17:15 -0500 Subject: [PATCH 3/7] Completed 4th part :ghost: --- 04week/loop.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/04week/loop.js b/04week/loop.js index 9b8009d19..cf34140de 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -37,8 +37,10 @@ for (const keys in persons) { } // 4. -for (const values in persons) { - +for (const keys in persons) { + if (keys === 'birthDate') { + console.log(persons[keys]); + } } // 1. When is a for loop better than a while loop? From 1971376272201ea0a0336395601d79e74fb7b8ea Mon Sep 17 00:00:00 2001 From: deytonk Date: Tue, 31 Oct 2017 12:22:54 -0500 Subject: [PATCH 4/7] my first for while loop :coffee: --- 04week/loop.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/04week/loop.js b/04week/loop.js index cf34140de..70523ec30 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -43,6 +43,16 @@ for (const keys in persons) { } } +// 5 +let num = 1; +while(num <= 1000) { + console.log(num); + num++; +} + +// 6 + + // 1. When is a for loop better than a while loop? // 2. How is the readability of the code affected? From fb6c7e14acaba3a658b52107c66a1693cfab6245 Mon Sep 17 00:00:00 2001 From: deytonk Date: Tue, 31 Oct 2017 13:31:45 -0500 Subject: [PATCH 5/7] my first do while loop :bowtie: --- 04week/loop.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/04week/loop.js b/04week/loop.js index 70523ec30..635fbf6d2 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -51,7 +51,12 @@ while(num <= 1000) { } // 6 - +let num = 1; +do { + console.log(num); + num++; +} +while(num <= 1000); // 1. When is a for loop better than a while loop? From 518fd85f6f6cab808e2c4dd2db6a5faca229c08e Mon Sep 17 00:00:00 2001 From: deytonk Date: Tue, 31 Oct 2017 15:19:22 -0500 Subject: [PATCH 6/7] start questions, just saving progress --- 04week/loop.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/04week/loop.js b/04week/loop.js index 635fbf6d2..a5038edd3 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -59,7 +59,9 @@ do { while(num <= 1000); // 1. When is a for loop better than a while loop? - -// 2. How is the readability of the code affected? + A for loop is better than a while loop when you do not only need the loop to run while something else happening. +// 2. How is the readability of the code affected + // 3. What is the difference between a for loop and a for...in loop? + // 4. What is the difference between a while loop and a do...while loop? From bb8c037b80616b3591b138bc6aab1e00fc943ae6 Mon Sep 17 00:00:00 2001 From: deytonk Date: Tue, 31 Oct 2017 16:53:08 -0500 Subject: [PATCH 7/7] answered questions --- 04week/loop.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/04week/loop.js b/04week/loop.js index a5038edd3..5248d64f7 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -59,9 +59,10 @@ do { while(num <= 1000); // 1. When is a for loop better than a while loop? - A for loop is better than a while loop when you do not only need the loop to run while something else happening. + // A for loop is better than a while loop when you know how many iterations there will be. // 2. How is the readability of the code affected - + The conditions in a for loop are clearly defined in the statement where as the while loop has less required conditions and therefor is easier to read and understand standalone, but is also more prone to errors. // 3. What is the difference between a for loop and a for...in loop? - + // A for...in loop is a for loop specified to iterate over the enumerable properties of an object. // 4. What is the difference between a while loop and a do...while loop? + // A do...while loop will repeat until a specific condition evaluates to false (which is defined after the statement) and a while loop will repeat as long as the condition (defined in the statement) evaluates to true.