Skip to content

Commit

Permalink
Added Shapes/Patterns in DOM using Loops in JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
iamzaidsoomro committed Oct 23, 2021
1 parent 6aed409 commit 5a8317e
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 0 deletions.
Binary file added Patterns Using Loops/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions Patterns Using Loops/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Patterns</title>
<link rel="icon" href="icon.png">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<style>
header h1 {
padding: 10px;
}
kbd{
font-family: "Terminal";
}
hr{
background: #35cc27;
height: 100px;
}
section{
display: flex;
margin-top: 100px;
}
.button-array{
margin: auto;
padding:50px;
}
button{
margin: 20px;
padding: 10px;
}
button img{
height: 30px;
width: 30px;
}
.result-section{
padding: 30px;
width: 300px;
border-radius: 10px;
}
#result{
margin: auto;
}
</style>
<script src="script.js"></script>
</head>
<body>
<header>
<h1 class="display-3 bg-dark text-light text-center">Shapes using JavaScript {}</h1>
</header>
<section class="container">
<div class="button-array">
<h4>Choose Shape</h4>
<hr class="col-md-4">
<button class="btn btn-success" onClick="rightAngleTriangleRight()">
<img src="rightTriangleRight.png" alt="Right Triangle Right">
</button>
<button class="btn btn-success" onClick="rightAngleTriangleInvertRight()">
<img src="rightTriangleInvertRight.png" alt="Right Triangle Invert Right">
</button>
<br>
<button class="btn btn-success" onClick="pyramid()">
<img src="pyramid.png" alt="Right Triangle Left">
</button>
<button class="btn btn-success" onClick="invertPyramid()">
<img src="pyramidInvert.png" alt="Invert Pyramid">
</button>
</div>
<div class="result-section bg-dark text-light border border-success">
<h4 class="display-6 text-center">Result</h4>
<hr class="text-success">
<div id="result" class="text-info"></div>
</div>
</section>
</section>
</body>
</html>
Binary file added Patterns Using Loops/pyramid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Patterns Using Loops/pyramidInvert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Patterns Using Loops/rightTriangleInvertRight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Patterns Using Loops/rightTriangleLeft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Patterns Using Loops/rightTriangleRight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions Patterns Using Loops/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Script for generating different shapes/patterns using loops in JavaScript
*/

/*
X
X X
X X X
X X X X
X X X X X
*/
function rightAngleTriangleRight(){
var lines = 5;
var triangle = "";
for(var i=0;i<lines;i++){
for(var j=0;j<=i;j++){
triangle += "X ";
}
triangle += "<br>"
}
document.getElementById('result').innerHTML = triangle;
document.getElementById('result').style.textAlign="start"
}
/*
X X X X X
X X X X
X X X
X X
X
*/
function rightAngleTriangleInvertRight(){
var lines = 5;
var triangle = "";
for(var i = 0; i < lines; i++){
for(var j = i; j < lines; j++) {
triangle += "X "
}
triangle += "<br>"
}
document.getElementById('result').innerHTML = triangle;
document.getElementById('result').style.textAlign="start"
}
/*
X
X X
X X X
X X X X
X X X X X
*/
function pyramid(){
var lines = 5;
var triangle = "";
for(var i = 0; i < lines; i++){
for(var j = i; j < lines; j++) {
triangle += " "
}
for(var j = 0; j <= i; j++) {
triangle += "X "
}
triangle += "<br>"
}
document.getElementById('result').innerHTML = triangle;
document.getElementById('result').style.textAlign="center"
}
/*
X X X X X
X X X X
X X X
X X
X
*/
function invertPyramid() {
var lines = 5;
var triangle = "";
for(var i = 0; i < lines; i++){
for(var j = 0; j < i; j++){
triangle += " "
}
for(var j = lines; j > i; j--){
triangle += "X "
}
triangle += "<br>"
}
document.getElementById('result').innerHTML = triangle;
document.getElementById('result').style.textAlign="center"
}

0 comments on commit 5a8317e

Please sign in to comment.