View difference between Paste ID: R0jBJSaZ and hSVBH2PY
SHOW: | | - or go back to the newest paste.
1-
// In Firefox, press Ctrl+Shift+K then copy and paste.
1+
// In Firefox, press Ctrl+Shift+K then copy, paste and run.
2
3
function printStar(n)
4
{
5
	var output = "";
6
	var level = n*2+1;
7
8
	for(var i = 1; i <= level; i++)
9
	{
10
		var isOddRow = i%2 == 1;
11
		var row = Math.floor((i+1)/2);
12
		var star = i < level ? row*2+1 : (row-1)*2+1;
13
		for(var j = 1; j <= star; j++)
14
		{
15
			var isOddCol = j%2 == 1;
16
			output += isOddRow || (!isOddRow && isOddCol) ? "*" : "-";
17
		}
18
		output += "\r\n";
19
	}
20
	return output;
21
}
22
23
print(printStar(3));