-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathscript.js
More file actions
158 lines (117 loc) Β· 3.9 KB
/
script.js
File metadata and controls
158 lines (117 loc) Β· 3.9 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//initialize state for question:
var stateOfProgram = 'question selection'; // 1) starts with input of question followed by 2) number of characters
var main = function (input) {
var myOutputValue = '';
//First Input on selection of question:
if (input == '1' && stateOfProgram == 'question selection') {
myOutputValue = 'Enter a number to draw!'
stateOfProgram = 'numOfCharacters';
} else if (input == '2' && stateOfProgram == 'question selection') {
myOutputValue = 'Enter a number to draw!'
stateOfProgram = 'square';
} else if (input == '3' && stateOfProgram == 'question selection') {
myOutputValue = 'Enter a number to draw!'
stateOfProgram = 'triangle';
} else if (input == '4' && stateOfProgram == 'question selection') {
myOutputValue = 'Enter a number to draw!'
stateOfProgram = 'outline square';
} else if (stateOfProgram == 'numOfCharacters') {
myOutputValue = numOfCharacter(input);
} else if (stateOfProgram == 'square') {
myOutputValue = square(input);
} else if (stateOfProgram == 'triangle') {
myOutputValue = triangle(input);
} else if (stateOfProgram == 'outline square') {
myOutputValue = outlineSquare(input);
}
return myOutputValue;
};
// Qn 1: Number of Characters
var numOfCharacter = function (input) {
var characterCounter = 0;
var outputDrawing = "";
var inputNumber = Number(input);
while (characterCounter < inputNumber) {
outputDrawing = outputDrawing + 'π';
console.log(outputDrawing);
characterCounter += 1;
};
return outputDrawing;
}
// Qn 2: Square
var square = function (input) {
var lineCounter = 0;
var outputDrawing = "";
var inputNumber = Number(input);
while (lineCounter < inputNumber) {
var characterCounter = 0;
while (characterCounter < inputNumber) {
outputDrawing = outputDrawing + 'π';
characterCounter += 1;
};
outputDrawing = outputDrawing + '<br>';
lineCounter += 1;
}
return outputDrawing;
}
// Qn 3: triangle
var triangle = function (input) {
var lineCounter = 0;
var inputNumber = Number(input);
var outputResult = "";
while (lineCounter < inputNumber) {
lineCounter += 1;
console.log('lineCounter is ' + lineCounter);
var characterCounter = 0;
var outputDrawing = "";
while (characterCounter < lineCounter) {
outputDrawing = outputDrawing + 'π';
characterCounter += 1;
}
outputResult = outputResult + outputDrawing + '<br>';
console.log('break is added');
console.log('outputResult is ' + outputResult);
}
return outputResult;
};
// Qn 4: outline square
var outlineSquare = function (input) {
var lineCounter = 0;
var outputDrawing = "";
var inputNumber = Number(input);
while (lineCounter < inputNumber) {
var characterCounter = 0;
//If lineCounter = 0 or lineCounter is the last line, print only fists
if (lineCounter == 0 || lineCounter == inputNumber - 1) {
while (characterCounter < inputNumber) {
outputDrawing = outputDrawing + 'β';
characterCounter += 1;
};
outputDrawing = outputDrawing + '<br>';
//else the lines being printed are the middle segments
} else {
//start the outputDrawing with a fist first
outputDrawing = outputDrawing + 'β';
//no matter the size, the inner lines will always have exactly 2 fists. Hence the number of inner thumbs up are exactly inputNumber - 2;
while (characterCounter < inputNumber - 2) {
outputDrawing = outputDrawing + 'π';
characterCounter += 1;
}
//end the outputDrawing with a fist and a break
outputDrawing = outputDrawing + 'β' + '<br>';
}
//increment the lineCounter to start printing the next line
lineCounter += 1;
}
return outputDrawing;
}
//Qn 5: Triangles within Square
//π
//β
//πββ
//ππβ
//πππ
//ββββ
//πβββ
//ππββ
//πππβ