From 3cba915af25fbf92d4f949508afcf4788f38a3f5 Mon Sep 17 00:00:00 2001 From: Shelley McIntyre <73217296+SLMcIntyre@users.noreply.github.com> Date: Mon, 30 Nov 2020 07:21:26 -0500 Subject: [PATCH 1/4] Loops lab problems 1-6 --- index.html | 12 ++++++++ loops.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 index.html create mode 100644 loops.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..77b81ba --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + + + + + JS Loops Lab + + + + + + \ No newline at end of file diff --git a/loops.js b/loops.js new file mode 100644 index 0000000..59cb9d3 --- /dev/null +++ b/loops.js @@ -0,0 +1,83 @@ +//JavaScript Loops Lab + +// 1) One to Ten +console.log ("One to Ten"); + +for (let i=1; i<=10; i++) { + console.log (i); +} + + +// 2) Squares +console.log ("Squares"); + +for (let i=1; i<=10; i++) { + let square = i*i; + console.log (square); +} + + +// 3) Even Under N +console.log ("Even Under N"); + +let n = 20; +for (let i=2; i Date: Mon, 30 Nov 2020 08:10:44 -0500 Subject: [PATCH 2/4] 1st draft of tableSquare --- loops.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/loops.js b/loops.js index 59cb9d3..3bd3943 100644 --- a/loops.js +++ b/loops.js @@ -65,17 +65,23 @@ console.log (triangle); // 7) Table Square console.log ("Table Square"); -/*let tableSquare = ""; -for (let i = 1; i<5; i++) { - for ( j = 2; j < 17; j + 2){ +let tableSquare = ""; +for (let i = 1; i <=4; i++) { + for ( j = 1; j <=4; j++){ + tableSquare = i *j + "|"; + console.log(tableSquare); + //tableSquare = i + j + (i *j) + "|"; + // console.log(tableSquare); } - tableSquare = `${i} + "|" + ${j}`; - console.log(tableSquare); + // tableSquare = tableSquare + ""; + } - - */ + + + + From 9859458e7a7456b9b8fb511c9c606f736529b1d0 Mon Sep 17 00:00:00 2001 From: Shelley McIntyre <73217296+SLMcIntyre@users.noreply.github.com> Date: Mon, 30 Nov 2020 12:22:48 -0500 Subject: [PATCH 3/4] corrected code for Table Square --- loops.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/loops.js b/loops.js index 3bd3943..23e24ae 100644 --- a/loops.js +++ b/loops.js @@ -66,18 +66,26 @@ console.log (triangle); // 7) Table Square console.log ("Table Square"); -let tableSquare = ""; - -for (let i = 1; i <=4; i++) { - for ( j = 1; j <=4; j++){ - tableSquare = i *j + "|"; - console.log(tableSquare); - //tableSquare = i + j + (i *j) + "|"; - // console.log(tableSquare); - } - // tableSquare = tableSquare + ""; + + + let tableSquare = ""; + let tableLine = ""; + for (let i = 1; i <=4; i++) { + for (let j = 1; j <=4; j++) { + tableLine += "|"+i*j+"|"; + } + + tableLine += "\n"; + tableSquare = tableLine; -} + } + console.log (tableSquare); + + + + + + From 0c3620c8714d23a56c4890807b79c0eacdbea1f7 Mon Sep 17 00:00:00 2001 From: Shelley McIntyre <73217296+SLMcIntyre@users.noreply.github.com> Date: Mon, 30 Nov 2020 12:28:19 -0500 Subject: [PATCH 4/4] added code for Table Square 2 --- loops.js | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/loops.js b/loops.js index 23e24ae..d951511 100644 --- a/loops.js +++ b/loops.js @@ -8,6 +8,7 @@ for (let i=1; i<=10; i++) { } + // 2) Squares console.log ("Squares"); @@ -17,6 +18,7 @@ for (let i=1; i<=10; i++) { } + // 3) Even Under N console.log ("Even Under N"); @@ -26,6 +28,7 @@ for (let i=2; i