From e0c73eec5e66e42fc9b15951a39a7cbb96061a66 Mon Sep 17 00:00:00 2001 From: sophiaratna Date: Sat, 29 Aug 2020 09:17:40 +0800 Subject: [PATCH 1/5] Complete project till Centre Square --- script.js | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 0f68729..225e5c8 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,132 @@ -// Please declare functions and variables above where they are used. +var myOutputValue = ""; +var gameStage = "first"; +var counter = 0; +var dimension =""; +var shapeCreated = ""; var main = function (input) { - var myOutputValue = 'hello world'; + if (gameStage=="first"){ + if (input =="square" || input == "triangle" || input == "upside down triangle" || input == "outline square" || input == "centre square"){ + shapeCreated = input; + myOutputValue = "Hello! You have requested to create " + shapeCreated + " shape! Please enter the dimension now! " + "
"; + gameStage = "second"; + } + else { + myOutputValue = 'Please enter either "square" or "triangle" or "upside down triangle" or "outline square" or "centre square"'; + } + console.log("Shape: "+ shapeCreated) ; + } + else if (gameStage=="second"){ + if (shapeCreated == "square"){ + dimension = input; + console.log ("gamestage: " + gameStage + ". And dimension: " + dimension) + while (counter < dimension) { + var innerCounter = 0; + while (innerCounter < dimension){ + myOutputValue = myOutputValue + " 😆 "; + innerCounter = innerCounter + 1; + } + counter = counter + 1; + myOutputValue = myOutputValue + "
"; + } + } + else if (shapeCreated == "triangle"){ + dimension = input; + while (counter < dimension){ + var innerCounter = -1; + while (innerCounter < counter){ + myOutputValue = myOutputValue + " 😆 "; + innerCounter = innerCounter + 1 ; + } + counter = counter + 1; + myOutputValue = myOutputValue + "
"; + } + } + else if (shapeCreated == "upside down triangle"){ + counter = input; + dimension = input; + while (counter != 0) { + var innerCounter = 0; + while (innerCounter" + counter = counter - 1; + } + } + else if (shapeCreated == "outline square"){ + while (counter < input){ + if (counter == 0 || counter == (input-1)){ + var innerCounter = 0; + while (innerCounter < input){ + myOutputValue = myOutputValue + " 😆 "; + innerCounter = innerCounter + 1; + } + } + + else if (counter != 0 || counter != (input-1)){ + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter == 0 || innerCounter == (input-1)){ + myOutputValue = myOutputValue + " 😆 "; + } + else{ + myOutputValue = myOutputValue + " 🥳 "; + } + innerCounter = innerCounter + 1; + } + } + counter = counter + 1; + myOutputValue = myOutputValue + "
"; + } + } + else if (shapeCreated == "centre square"){ + if (input%2 != 1){ + myOutputValue = "Please enter only odd-number dimension" + "
"; + } + else { + while (counter < input){ + if (counter == 0 || counter == (input-1)){ + var innerCounter = 0; + while (innerCounter < input){ + myOutputValue = myOutputValue + " 😆 "; + innerCounter = innerCounter + 1; + } + } + else if (counter == (input/2 - 0.5)){ + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter == 0 || innerCounter == (input-1)){ + myOutputValue = myOutputValue + " 😆 "; + } + else if (innerCounter == (input/2 - 0.5)){ + myOutputValue = myOutputValue + " 😈 "; + } + else { + myOutputValue = myOutputValue + " 🥳 "; + } + innerCounter = innerCounter + 1; + } + } + + else { + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter == 0 || innerCounter == (input-1)){ + myOutputValue = myOutputValue + " 😆 "; + } + else{ + myOutputValue = myOutputValue + " 🥳 "; + } + innerCounter = innerCounter + 1; + } + } + counter = counter + 1; + myOutputValue = myOutputValue + "
"; + } + } + } + } return myOutputValue; -}; +} \ No newline at end of file From 195e4f0d04698c7676ae7e2f44d22dd4ad59c023 Mon Sep 17 00:00:00 2001 From: sophiaratna Date: Sat, 29 Aug 2020 10:36:42 +0800 Subject: [PATCH 2/5] Completed project drawing with emjois --- script.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 225e5c8..0593d5f 100644 --- a/script.js +++ b/script.js @@ -6,7 +6,7 @@ var shapeCreated = ""; var main = function (input) { if (gameStage=="first"){ - if (input =="square" || input == "triangle" || input == "upside down triangle" || input == "outline square" || input == "centre square"){ + if (input =="square" || input == "triangle" || input == "upside down triangle" || input == "outline square" || input == "centre square" || input == "ring"){ shapeCreated = input; myOutputValue = "Hello! You have requested to create " + shapeCreated + " shape! Please enter the dimension now! " + "
"; gameStage = "second"; @@ -127,6 +127,89 @@ var main = function (input) { } } } + else if (shapeCreated == "ring"){ + while (counter < input){ + if (counter <= input/2-0.5){ + if (counter%2 == 0){ + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < counter || innerCounter > (input - counter - 1)){ + if (innerCounter%2 == 0){ + myOutputValue = myOutputValue + " B "; + } + else if (innerCounter%2 == 1){ + myOutputValue = myOutputValue + " A "; + } + innerCounter = innerCounter + 1; + } + else if (innerCounter >= counter && innerCounter < (input-counter)) { + myOutputValue = myOutputValue + " B "; + innerCounter = innerCounter + 1; + } + } + } + else { + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < counter || innerCounter > (input - counter - 1)){ + if (innerCounter%2 == 0){ + myOutputValue = myOutputValue + " B "; + } + else if (innerCounter%2 == 1){ + myOutputValue = myOutputValue + " A "; + } + innerCounter = innerCounter + 1; + } + else if (innerCounter >= counter && innerCounter < (input-counter)) { + myOutputValue = myOutputValue + " A "; + innerCounter = innerCounter + 1; + } + } + } + } + else{ + var equivalentCounter = input - counter - 1; + if (equivalentCounter%2 == 0){ + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ + if (innerCounter%2 == 0){ + myOutputValue = myOutputValue + " B "; + } + else if (innerCounter%2 == 1){ + myOutputValue = myOutputValue + " A "; + } + innerCounter = innerCounter + 1; + } + else if (innerCounter >= equivalentCounter && innerCounter < (input-equivalentCounter)) { + myOutputValue = myOutputValue + " B "; + innerCounter = innerCounter + 1; + } + } + } + else { + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ + if (innerCounter%2 == 0){ + myOutputValue = myOutputValue + " B "; + } + else if (innerCounter%2 == 1){ + myOutputValue = myOutputValue + " A "; + } + innerCounter = innerCounter + 1; + } + else if (innerCounter >= equivalentCounter && innerCounter < (input-equivalentCounter)) { + myOutputValue = myOutputValue + " A "; + innerCounter = innerCounter + 1; + } + } + } + } + counter = counter + 1; + myOutputValue = myOutputValue + "
"; + } + } } return myOutputValue; } \ No newline at end of file From 8f2022d8e0dd88e02ac89be9d0122cb29172ddd9 Mon Sep 17 00:00:00 2001 From: sophiaratna Date: Sat, 29 Aug 2020 11:34:01 +0800 Subject: [PATCH 3/5] replace emojis --- script.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/script.js b/script.js index 0593d5f..9e97654 100644 --- a/script.js +++ b/script.js @@ -135,15 +135,15 @@ var main = function (input) { while (innerCounter < input){ if (innerCounter < counter || innerCounter > (input - counter - 1)){ if (innerCounter%2 == 0){ - myOutputValue = myOutputValue + " B "; + myOutputValue = myOutputValue + " 😆 "; } else if (innerCounter%2 == 1){ - myOutputValue = myOutputValue + " A "; + myOutputValue = myOutputValue + " 😈 "; } innerCounter = innerCounter + 1; } else if (innerCounter >= counter && innerCounter < (input-counter)) { - myOutputValue = myOutputValue + " B "; + myOutputValue = myOutputValue + " 😆 "; innerCounter = innerCounter + 1; } } @@ -153,15 +153,15 @@ var main = function (input) { while (innerCounter < input){ if (innerCounter < counter || innerCounter > (input - counter - 1)){ if (innerCounter%2 == 0){ - myOutputValue = myOutputValue + " B "; + myOutputValue = myOutputValue + " 😆 "; } else if (innerCounter%2 == 1){ - myOutputValue = myOutputValue + " A "; + myOutputValue = myOutputValue + " 😈 "; } innerCounter = innerCounter + 1; } else if (innerCounter >= counter && innerCounter < (input-counter)) { - myOutputValue = myOutputValue + " A "; + myOutputValue = myOutputValue + " 😈 "; innerCounter = innerCounter + 1; } } @@ -174,15 +174,15 @@ var main = function (input) { while (innerCounter < input){ if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ if (innerCounter%2 == 0){ - myOutputValue = myOutputValue + " B "; + myOutputValue = myOutputValue + " 😆 "; } else if (innerCounter%2 == 1){ - myOutputValue = myOutputValue + " A "; + myOutputValue = myOutputValue + " 😈 "; } innerCounter = innerCounter + 1; } else if (innerCounter >= equivalentCounter && innerCounter < (input-equivalentCounter)) { - myOutputValue = myOutputValue + " B "; + myOutputValue = myOutputValue + " 😆 "; innerCounter = innerCounter + 1; } } @@ -192,15 +192,15 @@ var main = function (input) { while (innerCounter < input){ if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ if (innerCounter%2 == 0){ - myOutputValue = myOutputValue + " B "; + myOutputValue = myOutputValue + " 😆 "; } else if (innerCounter%2 == 1){ - myOutputValue = myOutputValue + " A "; + myOutputValue = myOutputValue + " 😈 "; } innerCounter = innerCounter + 1; } else if (innerCounter >= equivalentCounter && innerCounter < (input-equivalentCounter)) { - myOutputValue = myOutputValue + " A "; + myOutputValue = myOutputValue + " 😈 "; innerCounter = innerCounter + 1; } } From 6f62c76483a0dbfc725e7740016523103498b13c Mon Sep 17 00:00:00 2001 From: sophiaratna Date: Sat, 29 Aug 2020 13:19:20 +0800 Subject: [PATCH 4/5] add in myoutputvalue message --- script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.js b/script.js index 9e97654..66424ec 100644 --- a/script.js +++ b/script.js @@ -12,7 +12,7 @@ var main = function (input) { gameStage = "second"; } else { - myOutputValue = 'Please enter either "square" or "triangle" or "upside down triangle" or "outline square" or "centre square"'; + myOutputValue = 'Please enter either "square" or "triangle" or "upside down triangle" or "outline square" or "centre square" or "ring"'; } console.log("Shape: "+ shapeCreated) ; } From 7a9da3f5e0c8481e5cad3291e4d36211b6406040 Mon Sep 17 00:00:00 2001 From: sophiaratna Date: Sat, 29 Aug 2020 15:37:24 +0800 Subject: [PATCH 5/5] fixing ring code --- script.js | 218 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 164 insertions(+), 54 deletions(-) diff --git a/script.js b/script.js index 66424ec..0e5e255 100644 --- a/script.js +++ b/script.js @@ -128,88 +128,198 @@ var main = function (input) { } } else if (shapeCreated == "ring"){ - while (counter < input){ - if (counter <= input/2-0.5){ - if (counter%2 == 0){ - var innerCounter = 0; - while (innerCounter < input){ - if (innerCounter < counter || innerCounter > (input - counter - 1)){ - if (innerCounter%2 == 0){ - myOutputValue = myOutputValue + " 😆 "; + if (input%2==1){ + while (counter < input){ + if (counter <= input/2-0.5){ + if (counter%2 == 0){ + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < counter || innerCounter > (input - counter - 1)){ + if (innerCounter%2 == 0){ + myOutputValue = myOutputValue + " 😆 "; + } + else if (innerCounter%2 == 1){ + myOutputValue = myOutputValue + " 😈 "; + } + innerCounter = innerCounter + 1; } - else if (innerCounter%2 == 1){ - myOutputValue = myOutputValue + " 😈 "; + else if (innerCounter >= counter && innerCounter < (input-counter)) { + myOutputValue = myOutputValue + " 😆 "; + innerCounter = innerCounter + 1; } - innerCounter = innerCounter + 1; } - else if (innerCounter >= counter && innerCounter < (input-counter)) { - myOutputValue = myOutputValue + " 😆 "; + } + else { + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < counter || innerCounter > (input - counter - 1)){ + if (innerCounter%2 == 0){ + myOutputValue = myOutputValue + " 😆 "; + } + else if (innerCounter%2 == 1){ + myOutputValue = myOutputValue + " 😈 "; + } innerCounter = innerCounter + 1; + } + else if (innerCounter >= counter && innerCounter < (input-counter)) { + myOutputValue = myOutputValue + " 😈 "; + innerCounter = innerCounter + 1; + } } } } - else { - var innerCounter = 0; - while (innerCounter < input){ - if (innerCounter < counter || innerCounter > (input - counter - 1)){ - if (innerCounter%2 == 0){ - myOutputValue = myOutputValue + " 😆 "; + else{ + var equivalentCounter = input - counter - 1; + if (equivalentCounter%2 == 0){ + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ + if (innerCounter%2 == 0){ + myOutputValue = myOutputValue + " 😆 "; + } + else if (innerCounter%2 == 1){ + myOutputValue = myOutputValue + " 😈 "; + } + innerCounter = innerCounter + 1; } - else if (innerCounter%2 == 1){ - myOutputValue = myOutputValue + " 😈 "; + else if (innerCounter >= equivalentCounter && innerCounter < (input-equivalentCounter)) { + myOutputValue = myOutputValue + " 😆 "; + innerCounter = innerCounter + 1; } - innerCounter = innerCounter + 1; } - else if (innerCounter >= counter && innerCounter < (input-counter)) { - myOutputValue = myOutputValue + " 😈 "; + } + else { + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ + if (innerCounter%2 == 0){ + myOutputValue = myOutputValue + " 😆 "; + } + else if (innerCounter%2 == 1){ + myOutputValue = myOutputValue + " 😈 "; + } innerCounter = innerCounter + 1; + } + else if (innerCounter >= equivalentCounter && innerCounter < (input-equivalentCounter)) { + myOutputValue = myOutputValue + " 😈 "; + innerCounter = innerCounter + 1; + } } } } + counter = counter + 1; + myOutputValue = myOutputValue + "
"; } - else{ - var equivalentCounter = input - counter - 1; - if (equivalentCounter%2 == 0){ - var innerCounter = 0; - while (innerCounter < input){ - if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ - if (innerCounter%2 == 0){ - myOutputValue = myOutputValue + " 😆 "; + } + else{ + while (counter < input){ + if (counter < input/2){ + if (counter%2 == 0){ + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < counter || innerCounter > (input - counter - 1)){ + if ( innerCounter < input/2 && innerCounter%2 == 0){ + myOutputValue = myOutputValue + " 😆 "; + } + else if (innerCounter < input/2 && innerCounter%2 == 1){ + myOutputValue = myOutputValue + " 😈 "; + } + else if (innerCounter > input/2 && innerCounter%2==0){ + myOutputValue = myOutputValue + " 😈 " + } + else{ + myOutputValue = myOutputValue + " 😆 "; + } + innerCounter = innerCounter + 1; } - else if (innerCounter%2 == 1){ - myOutputValue = myOutputValue + " 😈 "; + else { + myOutputValue = myOutputValue + " 😆 "; + innerCounter = innerCounter + 1; } - innerCounter = innerCounter + 1; } - else if (innerCounter >= equivalentCounter && innerCounter < (input-equivalentCounter)) { - myOutputValue = myOutputValue + " 😆 "; + } + else { + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < counter || innerCounter > (input - counter - 1)){ + if ( innerCounter < input/2 && innerCounter%2 == 0){ + myOutputValue = myOutputValue + " 😆 "; + } + else if (innerCounter < input/2 && innerCounter%2 == 1){ + myOutputValue = myOutputValue + " 😈 "; + } + else if (innerCounter > input/2 && innerCounter%2==0){ + myOutputValue = myOutputValue + " 😈 " + } + else{ + myOutputValue = myOutputValue + " 😆 "; + } innerCounter = innerCounter + 1; + } + else { + myOutputValue = myOutputValue + " 😈 "; + innerCounter = innerCounter + 1; + } } } } - else { - var innerCounter = 0; - while (innerCounter < input){ - if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ - if (innerCounter%2 == 0){ - myOutputValue = myOutputValue + " 😆 "; + else{ + var equivalentCounter = input - counter - 1; + if (equivalentCounter%2 == 0){ + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ + if ( innerCounter < input/2 && innerCounter%2 == 0){ + myOutputValue = myOutputValue + " 😆 "; + } + else if (innerCounter < input/2 && innerCounter%2 == 1){ + myOutputValue = myOutputValue + " 😈 "; + } + else if (innerCounter > input/2 && innerCounter%2==0){ + myOutputValue = myOutputValue + " 😈 " + } + else{ + myOutputValue = myOutputValue + " 😆 "; + } + innerCounter = innerCounter + 1; } - else if (innerCounter%2 == 1){ - myOutputValue = myOutputValue + " 😈 "; + else { + myOutputValue = myOutputValue + " 😆 "; + innerCounter = innerCounter + 1; } - innerCounter = innerCounter + 1; } - else if (innerCounter >= equivalentCounter && innerCounter < (input-equivalentCounter)) { - myOutputValue = myOutputValue + " 😈 "; + } + else { + var innerCounter = 0; + while (innerCounter < input){ + if (innerCounter < equivalentCounter || innerCounter > (input - equivalentCounter - 1)){ + if ( innerCounter < input/2 && innerCounter%2 == 0){ + myOutputValue = myOutputValue + " 😆 "; + } + else if (innerCounter < input/2 && innerCounter%2 == 1){ + myOutputValue = myOutputValue + " 😈 "; + } + else if (innerCounter > input/2 && innerCounter%2==0){ + myOutputValue = myOutputValue + " 😈 " + } + else{ + myOutputValue = myOutputValue + " 😆 "; + } innerCounter = innerCounter + 1; + } + else { + myOutputValue = myOutputValue + " 😈 "; + innerCounter = innerCounter + 1; + } } } } + counter = counter + 1; + myOutputValue = myOutputValue + "
"; } - counter = counter + 1; - myOutputValue = myOutputValue + "
"; - } + } } - } - return myOutputValue; -} \ No newline at end of file + } + return myOutputValue; +} +