From a4e06da19ab525c5daf7e7b068455c5217853c10 Mon Sep 17 00:00:00 2001 From: Tajanae Boone Date: Wed, 25 Nov 2020 18:56:41 -0500 Subject: [PATCH] loops finished --- README.md | 4 +-- index.html | 15 ++++++++++ loops.js | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 index.html create mode 100644 loops.js diff --git a/README.md b/README.md index 1872c51..2986003 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,11 @@ n = 20 16
18
-## 4) Sum +## 4) Sum ########******* ******* Calculates the sum of the number from n to, but not including m, and returns the answer. ### Example
-(5,10) +(5,10) *** Output *** diff --git a/index.html b/index.html new file mode 100644 index 0000000..3f2d87f --- /dev/null +++ b/index.html @@ -0,0 +1,15 @@ + + + + + + Document + + + + + + + + + diff --git a/loops.js b/loops.js new file mode 100644 index 0000000..9786e57 --- /dev/null +++ b/loops.js @@ -0,0 +1,88 @@ +//Part 1 + for (i = 1; i < 11; i++) { + console.log(i); + } + +//Part 2 + for (i = Math.sqrt(1); i <= 10; i++) { + console.log(i*i); +} + +//Part 3 + let n = 20 + for (i = 1; i < n; i++) { + if (i % 2 === 0) + console.log(i); +} + +//Part 4 +function numberSum(n,m) { + let total = 0; + for (let i = n; i < m; i++){ + total += i; +} + return total; +} + console.log(numberSum()); + + +//Part 5 + let AreWeThere = prompt ("Are we there yet?"); + + if (AreWeThere === "yes") { + alert("Good!"); +} else { + while (AreWeThere !== "yes") + AreWeThere = prompt ("Are we there yet?"); + alert("Good!"); +} + +//Triangle Part 6 + + let output = " "; + + for (let k=1; k<6; k++) { + output += k + " "; + console.log(output); +} + +//Part 7 + +function makeSmallMultiplicationTable() { + // print columns and row numbers + const maxTotalRows = 4; + const maxTotalColumns = 4; + let completedTable = ""; + for (let row = 1; row <= maxTotalRows; row++) { + //OUTER LOOP + for (let column = 1; column <= maxTotalColumns; column++) { + //INNER LOOP + completedTable = completedTable + `|${row * column}`; +} + // end first outer loop + completedTable = completedTable + "|\n"; +} + return completedTable; +} + console.log(makeSmallMultiplicationTable(4,4)) + +// +function makeSmallMultiplicationTable(maxTotalRows, maxTotalColumns) { + // print columns and row numbers + // const maxTotalRows = 4; + // const maxTotalColumns = 4; + let completedTable = ""; + for (let row = 1; row <= maxTotalRows; row++) { + //OUTER LOOP + for (let column = 1; column <= maxTotalColumns; column++) { + //INNER LOOP + completedTable = completedTable + `|${row * column}`; + } + // end first outer loop + completedTable = completedTable + "|\n"; + } + return completedTable; + } + console.log(makeSmallMultiplicationTable(6, 6)) + + \ No newline at end of file