-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs--q1-7--patterns.html
94 lines (89 loc) · 2.23 KB
/
js--q1-7--patterns.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
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
<!--
Q1.7 WAP to print the following pattern by using JS:
[a]
*
* *
* * *
* * * *
* * * * *
[b]
* * * * *
* * * *
* * *
* *
*
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JS Task 1.1</title>
<link rel="stylesheet" href="style.css" />
<style>
main {
display: flex;
border: none;
}
form{
row-gap: 1.5rem;
}
table {
grid-template-columns: 0.8fr 0.8fr;
row-gap: 1rem;
padding: 0;
}
table tr {
justify-content: center;
align-items: center;
border: 2px solid black;
min-height: 5rem;
}
.container1,
.container2 {
box-sizing: border-box;
font-size: 2rem;
padding: 2rem;
}
</style>
</head>
<body>
<main>
<form action="">
<h1>Print Star Patterns</h1>
<label for="">
Enter Number of Lines for pattern
<input type="text" placeholder="Enter value.." />
</label>
<button type="button" onclick="printStars()">Print Pattern</button>
<table>
<tr>
<td class="container1"></td>
<td class="container2"></td>
</tr>
</table>
</form>
</main>
<script>
function printStars() {
const line = document.querySelector("input").value;
document.querySelector(".container1").innerHTML = "";
document.querySelector(".container2").innerHTML = "";
for (var row = 0; row <= line; row++) {
console.log("--for loop executed--");
for (var col = line; col > row; col--) {
console.log("first loop", col);
document.querySelector(".container1").innerHTML += "* ";
}
for (var col = 0; col < row; col++) {
console.log("second loop", col);
document.querySelector(".container2").innerHTML += "* ";
}
document.querySelector(".container1").innerHTML += "<br>";
document.querySelector(".container2").innerHTML += "<br>";
console.log("End of for loop");
}
}
</script>
</body>
</html>