From 61de6b989311854f0c3ed9e16cc935a7eade9427 Mon Sep 17 00:00:00 2001 From: michael-mcmasters Date: Tue, 24 Nov 2020 14:22:55 -0500 Subject: [PATCH 1/3] Create index.html and import script.js --- index.html | 9 +++++++++ script.js | 1 + 2 files changed, 10 insertions(+) create mode 100644 index.html create mode 100644 script.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..6439e64 --- /dev/null +++ b/index.html @@ -0,0 +1,9 @@ + + + + + + + + Hello World + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..6b2b3db --- /dev/null +++ b/script.js @@ -0,0 +1 @@ +console.log("hello world"); From fa74e0042bd3c80dc0119cd500d122826d75a646 Mon Sep 17 00:00:00 2001 From: michael-mcmasters Date: Tue, 24 Nov 2020 15:06:21 -0500 Subject: [PATCH 2/3] Complete steps 1 through 8 --- script.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 6b2b3db..cd34e4e 100644 --- a/script.js +++ b/script.js @@ -1 +1,73 @@ -console.log("hello world"); +// 1. One to Ten. +// for (let i = 1; i <= 10; i++) { +// console.log(i); +// } + +// 2. Squares +// for (let i = 0; i <= 100; i++) { +// let num = Math.sqrt(i); +// if (num % 1 == 0) { +// console.log(i); +// } +// } + +// 3. Even Under N +// let n = 20; +// for (let i = 0; i < 20; i++) { +// if (i % 2 == 0) +// console.log(i); +// } + +// 4. Sum +// let sum = 0; +// for (let i = 5; i < 10; i++) { +// sum += i; +// } +// console.log(sum); + +// 5. Are We There Yet +// let weAreThere = false; +// while (!weAreThere) { +// let userAnswer = prompt("Are we there yet?"); +// if (userAnswer.toLowerCase() == "yes") +// weAreThere = true; +// } + +// 6. Triangle +// let rows = 5; +// for (let i = 1; i <= rows; i++) { +// let stars = ""; +// for (let j = 1; j <= i; j++) { +// stars += "*"; +// } +// console.log(stars); +// } + +// 7. Table Square +let rows = 4; +let columns = 4; +console.log(createMultiplicationTable(rows, columns)); + +// 8. Table Square 2 +rows = 6; +columns = 6; +console.log(createMultiplicationTable(rows, columns)); + +// (Helper function) +function createMultiplicationTable(rows, columns) { + let table = ""; + + for (let row = 1; row <= rows; row++) { + for (let column = 1; column <= columns; column++) { + let number = row * column; // It's a multiplication table. So number is row times column. (For example: 25 is row 5 times column 5... 4 is row 2 times column 2... etc.) + if (number < 10) { + table += ` ${number} |`; // single digit numbers have two spaces before them. + } else { + table += ` ${number} |`; // double digit numbers have one space before them. + } + } + table += "\n"; // Once all columns in a row are filled, go to next line. + } + + return table; +} \ No newline at end of file From 74fd2b33eb13801f846fe2a126ac13fd4a404b10 Mon Sep 17 00:00:00 2001 From: michael-mcmasters Date: Sat, 28 Nov 2020 14:19:46 -0500 Subject: [PATCH 3/3] Fix table so that there is a pipe at the beginning of every row --- script.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index cd34e4e..34cf295 100644 --- a/script.js +++ b/script.js @@ -59,11 +59,14 @@ function createMultiplicationTable(rows, columns) { for (let row = 1; row <= rows; row++) { for (let column = 1; column <= columns; column++) { - let number = row * column; // It's a multiplication table. So number is row times column. (For example: 25 is row 5 times column 5... 4 is row 2 times column 2... etc.) - if (number < 10) { - table += ` ${number} |`; // single digit numbers have two spaces before them. + if (column == 1) { + table += "|"; // Add | to the beginning of the first column of every row. + } + let number = row * column; // It's a multiplication table. So number is row times column. (For example: row 5 column 5 is 25... row 4 column 5 is 20... etc) + if (column > 1 && number < 10) { + table += ` ${number} |`; // Single digit numbers have two spaces before them (except when in the first column.) } else { - table += ` ${number} |`; // double digit numbers have one space before them. + table += ` ${number} |`; // Double digit numbers have one space before them. } } table += "\n"; // Once all columns in a row are filled, go to next line.