From f02c0c894f7079e6aad547b41eb62092b2c41c9f Mon Sep 17 00:00:00 2001 From: Low Wei Jun Date: Thu, 3 Sep 2020 15:56:44 +0800 Subject: [PATCH] wow --- script.js | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 0f68729..165dce0 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,103 @@ // Please declare functions and variables above where they are used. +//define global variable for shapeInput to store data across all functions +var shapeInput; + +var numberOfCharacters = function (input) { + var counter = 0; + var myOutputValue = ''; + while (counter < input) { + myOutputValue = myOutputValue + '👍'; + counter = counter + 1; + } + return myOutputValue; +} + +var square = function (input) { + var myOutputValue = ''; + var dimensions = Number(input); + var lineCounter = 0; + while (lineCounter < dimensions) { + var columnCounter = 0; + while (columnCounter < dimensions) { + myOutputValue = myOutputValue + '👍'; + columnCounter = columnCounter + 1; + } + myOutputValue = myOutputValue + '
'; + lineCounter = lineCounter + 1; + } + return myOutputValue; +} + +var triangle = function (input) { + var myOutputValue = ''; + var dimensions = Number(input); + var lineCounter = 0; + while (lineCounter < dimensions) { + var columnCounter = 0; + while (columnCounter < lineCounter) { + myOutputValue = myOutputValue + '👍'; + columnCounter = columnCounter + 1; + } + myOutputValue = myOutputValue + '
'; + lineCounter = lineCounter + 1; + } + return myOutputValue; +} var main = function (input) { - var myOutputValue = 'hello world'; + //get user input for either square or triangle + if (input == 'square' || input == 'triangle') { + shapeInput = input; + console.log(shapeInput); + return 'You have entered ' + shapeInput + ' . Please enter the dimensions.'; + } + //once user inputs shape or square, user would next input dimensions + var dimensions = Number(input); + console.log(dimensions); + //if use inputs square, call square function with dimensions entered by user + if (shapeInput === 'square') { + return square(dimensions); + } + //if use inputs triangle, call triangle function with dimensions entered by user + if (shapeInput === 'triangle') { + return triangle(dimensions); + } +} + +var upsideDownTriangle = function (input) { + var myOutputValue = ''; + var length = Number(input); + var columnCounter = 0; + while (columnCounter < lineCounter) { + var lineCounter = 0; + while (lineCounter < length - columnCounter) { + myOutputValue += '👍'; + columnCounter += 1; + } + myOutputValue = myOutputValue + '👍'; + counter = counter + 1; + } + return myOutputValue; +}; + +var outlineSquare = function (input) { + var myOutputValue = ''; + var length = Number(input); + var outerCounter = 0; + while (outerCounter < length) { + var innerCounter = 0; + while (innerCounter < length) { + if (outerCounter == 0 || outerCounter == length - 1 + || innerCounter == 0 || innerCounter == length - 1) { + myOutputValue = myOutputValue + '✊'; + } else { + myOutputValue = myOutputValue + '👍'; + } + innerCounter = innerCounter + 1; + } + myOutputValue = myOutputValue + '
'; + outerCounter = outerCounter + 1; + } return myOutputValue; }; +//i gave up doing rings :( but will look thru the solution proivided \ No newline at end of file