forked from rocketacademy/basics-drawing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
115 lines (98 loc) Β· 3.38 KB
/
script.js
File metadata and controls
115 lines (98 loc) Β· 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Please declare functions and variables above where they are used.
// Setting a counter to limit the amount of times we loop
var gameMode = 'waiting for selection';
var triangleCounter = 1;
var outerCounter = 0;
var myOutputValue = '';
var selection = ';'
var upsideDownCounter = 0;
var main = function (input) {
if (gameMode == 'waiting for selection') {
gameMode = input;
myOutputValue = 'You chose the ' + gameMode + ' game mode.<br>';
} else if (gameMode == 'default') {
while (outerCounter < input) {
// Adding a thumbs up emoji to output
myOutputValue = myOutputValue + 'π';
// Increasing counter by 1
outerCounter = outerCounter + 1;
}
} else if (gameMode == 'square') {
while (outerCounter < input) {
// declaring inntercounter here is important as we need it's value to reset everytime the function runs
var innerCounter = 0;
while (innerCounter < input) {
myOutputValue = myOutputValue + 'π';
innerCounter = innerCounter + 1;
};
// Adding a <br> tag after the innerCounter ensures only one <br> tag per line of emojis
myOutputValue = myOutputValue + '<br>';
outerCounter = outerCounter + 1;
};
} else if (gameMode == 'triangle') {
while (outerCounter < input) {
// Declaring lineCounter here allows us to incrementally add more emojis per line before each <br> tag
var lineCounter = 0;
while (lineCounter < triangleCounter) {
myOutputValue = myOutputValue + 'π';
lineCounter = lineCounter + 1;
};
triangleCounter = triangleCounter + 1;
outerCounter = outerCounter + 1;
myOutputValue = myOutputValue + '<br>';
};
} else if (gameMode == 'upsidedown') {
var lineCounter = input;
while (outerCounter < input) {
var extraCounter = 0;
while (extraCounter < lineCounter) {
myOutputValue = myOutputValue + 'π';
extraCounter = extraCounter + 1;
};
lineCounter = lineCounter - 1;
outerCounter = outerCounter + 1;
myOutputValue = myOutputValue + '<br>';
};
}
return myOutputValue;
};
// This is the solution for Square
/*
var main = function (input) {
var outerCounter = 0;
var myOutputValue = '';
while (outerCounter < input) {
// declaring inntercounter here is important as we need it's value to reset everytime the function runs
var innerCounter = 0;
while (innerCounter < input) {
myOutputValue = myOutputValue + 'π';
innerCounter = innerCounter + 1;
};
// Adding a <br> tag after the innerCounter ensures only one <br> tag per line of emojis
myOutputValue = myOutputValue + '<br>';
outerCounter = outerCounter + 1;
};
return myOutputValue;
};
*/
// This is the solution for Triangle
/*
var main = function (input) {
// brCounter is the variable to manipulate the number of emojis before each <br> tag
var brCounter = 1;
var outerCounter = 0;
var myOutputValue = '';
while (outerCounter < input) {
// Declaring lineCounter here allows us to incrementally add more emojis per line before each <br> tag
var lineCounter = 0;
while (lineCounter < brCounter) {
myOutputValue = myOutputValue + 'π';
lineCounter = lineCounter + 1;
};
brCounter = brCounter + 1;
outerCounter = outerCounter + 1;
myOutputValue = myOutputValue + '<br>';
};
return myOutputValue;
};
*/