forked from TelerikAcademy/JavaScript-Fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path04. print-triangle.html
36 lines (32 loc) · 911 Bytes
/
04. print-triangle.html
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Functions - Triangle</title>
<link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
<label for="tb-number">Number: </label>
<input id="tb-number" type="text" class="js-console-input" />
<a href="#" class="js-console-btn" onclick="onPrintTriangleBtnClick()">Print triangle</a>
<div id="js-console"></div>
<script src="scripts/js-console.js"></script>
<script>
function onPrintTriangleBtnClick() {
var line,
n = jsConsole.readFloat('#tb-number');
for (line = 1; line <= n; line++)
printLine(1, line);
for (line = n - 1; line >= 1; line--)
printLine(1, line);
jsConsole.writeLine('----------------');
}
function printLine(start, end) {
var i;
for (i = start; i <= end; i++) {
jsConsole.write(i + ' ');
}
jsConsole.writeLine();
}
</script>
</body>
</html>