From 05e0c0f4e61c6c129885cd6d075c040cfd0b2f14 Mon Sep 17 00:00:00 2001 From: Jim Schaefer Date: Mon, 4 Feb 2019 22:43:16 -0600 Subject: [PATCH 1/3] turning in loops assignment --- 04week/loop.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/04week/loop.js b/04week/loop.js index e69de29bb..4b9186934 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -0,0 +1,58 @@ +// for loop +const cars = ["ford", "chevrolet", "dodge", "mazda", "fiat"]; +for (let i = 0; i < cars.length; i++) { + console.log(cars[i]) +} +// for...in loop +const persons = { + firstName: "Jane", + lastName: "Doe", + birthDate: "Jan 5, 1925", + gender: "female", +} + +// Use a for...in loop to console.log each key. + +var text = ""; +var x = Object.keys(persons); +for (x in persons) { + text += x + " "; +} +console.log(text); + +// Use a for...in loop and if state to console.log the value associated with the key birthDate. + +var text1 = ""; +var x = Object.keys(persons); +for (x in persons) { + if (x === 'birthDate') { + text1 += persons[x]; + } +} +console.log(text1); + +// while loop +let number = 0; +while (number < 1000){ + number ++; + console.log(number); +} + +//do while +let digit = 0; +do { + digit += 1; + console.log(digit); +} while (digit < 1000); + +// 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? + From 0d5ce948e2fcbb36d3cbb923882690bb09590d2c Mon Sep 17 00:00:00 2001 From: Jim Schaefer Date: Tue, 5 Feb 2019 12:42:19 -0600 Subject: [PATCH 2/3] turning in updated loop assignment --- 04week/loop.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/04week/loop.js b/04week/loop.js index 4b9186934..b9f08e376 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -46,13 +46,11 @@ do { } while (digit < 1000); // When is a for loop better than a while loop? - - -// How is the readability of the code affected? - + // A for loop runs "n" times but a while loop runs until a certain condition becomes false. If the initial condition is false, the while loop wont run at all. So if your condition is initially false, a for loop is better. // What is the difference between a for loop and a for...in loop? - + // A for loop repeats until a specified condition evaluates to false. + //The for...in statement iterates a specified variable over all the enumerable properties of an object. For each distinct property, JavaScript executes the specified statements. // What is the difference between a while loop and a do...while loop? - + // The do...while statement repeats until a specified condition evaluates to false. A while statement executes its statements as long as a specified condition evaluates to true. \ No newline at end of file From c38e0ab04dd7b3e589a39843dc5a7d7b6cf9ec98 Mon Sep 17 00:00:00 2001 From: Jim Schaefer Date: Tue, 5 Feb 2019 12:44:38 -0600 Subject: [PATCH 3/3] turning in update loop assignment --- 04week/loop.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/04week/loop.js b/04week/loop.js index b9f08e376..bea853337 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -53,4 +53,6 @@ do { //The for...in statement iterates a specified variable over all the enumerable properties of an object. For each distinct property, JavaScript executes the specified statements. // What is the difference between a while loop and a do...while loop? - // The do...while statement repeats until a specified condition evaluates to false. A while statement executes its statements as long as a specified condition evaluates to true. \ No newline at end of file + // The do...while statement repeats until a specified condition evaluates to false. A while statement executes its statements as long as a specified condition evaluates to true. + + \ No newline at end of file