From eba571e12aa6e832d6f5d1e4c3004106415229bf Mon Sep 17 00:00:00 2001 From: cynthcxy Date: Mon, 28 Sep 2020 22:21:47 +0800 Subject: [PATCH 1/3] add drawing exercise up to triangle rules --- script.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index bbe8a29..059f35e 100644 --- a/script.js +++ b/script.js @@ -1,4 +1,20 @@ var main = function (input) { - var myOutputValue = 'hello world'; + var myOutputValue = ''; + + var rowCounter = 0; + + while (rowCounter < input) { + + var columnCounter = 0; + + while (columnCounter < rowCounter + 1) { + myOutputValue = myOutputValue + '🍔'; + columnCounter = columnCounter + 1; + } + myOutputValue = myOutputValue + '
'; + rowCounter = rowCounter + 1; + } + return myOutputValue; }; + From 800e5a2c4e324e44b8359ae590801508c3c3bee3 Mon Sep 17 00:00:00 2001 From: cynthcxy Date: Mon, 28 Sep 2020 22:49:13 +0800 Subject: [PATCH 2/3] changed to outline square exercise --- script.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/script.js b/script.js index 059f35e..0aa9c71 100644 --- a/script.js +++ b/script.js @@ -1,20 +1,38 @@ var main = function (input) { var myOutputValue = ''; + var firstRowLength = 0; - var rowCounter = 0; + // draw first row (looped with input) + while (firstRowLength < input) { + myOutputValue = myOutputValue + '😀'; + firstRowLength = firstRowLength + 1; + } + myOutputValue = myOutputValue + '
'; - while (rowCounter < input) { + var rowCounter = 0; + //draw rows between (input - 2) as it doesnt draw the first and last lines + while (rowCounter < (input - 2)) { + //start row with smiley + myOutputValue = myOutputValue + '😀'; var columnCounter = 0; - - while (columnCounter < rowCounter + 1) { + //draw (input - 2) burgers between the smileys + while (columnCounter < (input - 2)) { myOutputValue = myOutputValue + '🍔'; columnCounter = columnCounter + 1; } - myOutputValue = myOutputValue + '
'; + //end row with smiley and break + myOutputValue = myOutputValue + '😀
'; rowCounter = rowCounter + 1; } + // draw last row (looped with input) + var lastRowLength = 0; + while (lastRowLength < input) { + myOutputValue = myOutputValue + '😀'; + lastRowLength = lastRowLength + 1; + } return myOutputValue; }; + From f7d91e3f5cbaeca48d4d0a01327fc261913bd8b3 Mon Sep 17 00:00:00 2001 From: cynthcxy Date: Mon, 28 Sep 2020 22:55:06 +0800 Subject: [PATCH 3/3] added condition to draw last row only if input is at least 2 --- script.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/script.js b/script.js index 0aa9c71..2fa831a 100644 --- a/script.js +++ b/script.js @@ -26,11 +26,13 @@ var main = function (input) { rowCounter = rowCounter + 1; } - // draw last row (looped with input) - var lastRowLength = 0; - while (lastRowLength < input) { - myOutputValue = myOutputValue + '😀'; - lastRowLength = lastRowLength + 1; + // draw last row (looped with input) if input is at least 2 + if (input > 1) { + var lastRowLength = 0; + while (lastRowLength < input) { + myOutputValue = myOutputValue + '😀'; + lastRowLength = lastRowLength + 1; + } } return myOutputValue; };