From b45e77b101b977764b5bd42f77d3c3f6773abb4a Mon Sep 17 00:00:00 2001 From: geldridge13 <73252369+geldridge13@users.noreply.github.com> Date: Tue, 1 Dec 2020 13:37:43 -0500 Subject: [PATCH] complete loops lab --- index.html | 9 ++++++ loops.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 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..31d67e4 --- /dev/null +++ b/index.html @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/loops.js b/loops.js new file mode 100644 index 0000000..2f7675d --- /dev/null +++ b/loops.js @@ -0,0 +1,85 @@ +//PROBLEM 1 + +for(i=1;i<=10;i++) { + console.log(i); +} + +//PROBLEM 2 + +for (let i=1;i<=10;i++){ + console.log(i * i) +} + +//PROBLEM 3 + +let n = 20 +for (let i=1;i<=n;i++) + if (i % 2 == 0){ + console.log(i) + } + +//PROBLEM 4 + +//PROBLEM 5 + +do { +user=prompt("Are we there yet?") +} while (user !== "Yes") +alert("Good!") + +//PROBLEM 6 + +for (let i=1;i<=5;i++){ + let stars = "" + for (let j = 1;j <= i; j++){ + stars += "*"; + } + console.log(stars) +} + + +//PROBLEM 7 +rows = 4 +columns = 4 + +for (let currentRow = 1; currentRow <= rows; currentRow++) { + let num = "" + for (let currentCol = 1; currentCol <= columns; currentCol++){ + let product = "" + product += currentCol * currentRow + if (currentCol === 1){ + num += `|` + } + if (product < 10 && currentCol > 1) { + num += ` ${product} |` + } else { + num += ` ${product} |` + } + } + console.log(num) +} + +//PROBLEM 8 +rows = 6 +columns = 6 + +for (let currentRow = 1; currentRow <= rows; currentRow++) { + let num = "" + for (let currentCol = 1; currentCol <= columns; currentCol++){ + let product = "" + product += currentCol * currentRow + if (currentCol === 1){ + num += `|` + } + if (product < 10 && currentCol > 1) { + num += ` ${product} |` + } else { + num += ` ${product} |` + } + } + console.log(num) +} + + + +