From 059764c8d594abf89b9a2518cb43cfe2d4ec6e8c Mon Sep 17 00:00:00 2001 From: Karen-Heng Date: Sat, 19 Dec 2020 10:31:00 +0800 Subject: [PATCH] Loops Submission --- package.json | 2 +- script.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 90af81e..da8bab3 100644 --- a/package.json +++ b/package.json @@ -21,4 +21,4 @@ "eslint-config-airbnb-base": "^14.2.0", "eslint-plugin-import": "^2.22.0" } -} \ No newline at end of file +} diff --git a/script.js b/script.js index bbe8a29..d41d21f 100644 --- a/script.js +++ b/script.js @@ -1,4 +1,76 @@ +// NUMBER OF CHARACTERS +var counter = 0; + var main = function (input) { - var myOutputValue = 'hello world'; + var myOutputValue = ''; + + while (counter < input) { + myOutputValue = myOutputValue + '👍'; + counter = counter + 1; + console.log(counter); + } + console.log(myOutputValue); return myOutputValue; }; + +// SQUARE EXERCISE +var main = function (input) { + var myOutputValue = ''; + var lineCounter = 0; + + while (lineCounter < input) { + var columnCounter = 0; + while (columnCounter < input) { + myOutputValue = myOutputValue + '👍'; + console.log(myOutputValue + 'inner'); + columnCounter = columnCounter + 1; + } + myOutputValue = myOutputValue + '
'; + lineCounter = lineCounter + 1; + } + console.log(myOutputValue + 'outer'); + return myOutputValue; +}; + +// TRIANGLE EXERCISE +var main = function (input) { + var myOutputValue = ''; + var lineCounter = 0; + + while (lineCounter < input) { + var columnCounter = 0; + while (columnCounter < lineCounter) { + myOutputValue = myOutputValue + '👍'; + console.log(myOutputValue + 'inner'); + columnCounter = columnCounter + 1; + } + lineCounter = lineCounter + 1; + myOutputValue = myOutputValue + '👍
'; + } + console.log(myOutputValue + 'outer2'); + return myOutputValue; +}; + +// OUTLINE SQUARE EXERCISE +var main = function (input) { + var lineCounter = 0; + + while (lineCounter < input) { + var myOutputValue = '✊✊✊✊'; + var columnCounter = 0; + while (columnCounter < input) { + if (columnCounter == 1 || columnCounter == 2) { + myOutputValue = myOutputValue + '✊👍👍✊'; + } + if (columnCounter == 3) { + myOutputValue = myOutputValue + '✊✊✊✊'; + } + console.log(myOutputValue + 'inner'); + columnCounter = columnCounter + 1; + myOutputValue = myOutputValue + '
'; + } + console.log(myOutputValue + 'outer'); + lineCounter = lineCounter + 1; + return myOutputValue; + } +};