Last active
December 22, 2021 02:49
-
-
Save nairihar/c5d804c35f60288bcc81f39659e10352 to your computer and use it in GitHub Desktop.
JavaScript Armenia | Triangle patterns | LIVE session #1 | Building and discussing 4 triangles via JavaScript !!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
** | |
*** | |
**** | |
***** | |
*/ | |
// function draw1() { | |
// for (let i = 1; i <= 5; i++) { | |
// for (let j = 0; j < i; j++) { | |
// document.write('*'); | |
// } | |
// document.write('<br />'); | |
// } | |
// } | |
// draw1(); | |
// function draw1() { | |
// for (let i = 1; i <= 5; i++) { | |
// document.write(star.repeat(i), '<br />'); | |
// } | |
// } | |
// draw1(); | |
// function draw1() { | |
// let line = ''; | |
// for (let i = 1; i <= 5; i++) { | |
// line += '*'; | |
// document.write(line, '<br />'); | |
// } | |
// } | |
// draw1(); | |
/* | |
***** | |
**** | |
*** | |
** | |
* | |
*/ | |
// const STAR = '*'; | |
// const NEW_LINE = '<br />'; | |
// function draw2(length) { | |
// let line = STAR.repeat(length); // ****** | |
// for (let i = 0; i < length; i++) { | |
// document.write(line, NEW_LINE); | |
// line = line.slice(1); | |
// } | |
// } | |
// draw2(6); | |
/* | |
***** | |
**** | |
*** | |
** | |
* | |
*/ | |
// const STAR = '*'; | |
// const NEW_LINE = '<br />'; | |
// function drawRec(lvl=5) { | |
// if (lvl===0) { | |
// return; | |
// } | |
// const line = STAR.repeat(lvl); | |
// document.write(line, NEW_LINE); | |
// return drawRec(--lvl) | |
// } | |
// drawRec(); | |
// function drawRec(lvl=5) { | |
// debugger; | |
// if (lvl===0) { | |
// return; | |
// } | |
// const line = STAR.repeat(lvl); | |
// document.write(line, NEW_LINE); | |
// return drawRec(--lvl) | |
// } | |
// drawRec(); | |
/* | |
***** | |
**** | |
*** | |
** | |
* | |
*/ | |
// const STAR = '*'; | |
// const NEW_LINE = '<br />'; | |
// const SPACE = '_'; | |
// function draw3(lvl) { | |
// let spaces = '' | |
// for (let n = lvl; n >= 0; n--) { | |
// let line = STAR.repeat(n); | |
// document.write(spaces, line, NEW_LINE); | |
// spaces += SPACE; | |
// } | |
// } | |
// draw3(5) | |
/* | |
* | |
** | |
*** | |
**** | |
***** | |
****** | |
*/ | |
const STAR = '*'; | |
const NEW_LINE = '<br />'; | |
const SPACE = ' '; | |
function draw4(lvl) { | |
for (let n = lvl; n >= 0; n--) { | |
let spaces = SPACE.repeat(n) | |
let stars = STAR.repeat(lvl-n); | |
document.write(spaces, stars, NEW_LINE); | |
} | |
} | |
draw4(5) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SPACE = ' '; | |
const NEW_LINE = '<br>'; | |
const STAR = '*'; | |
function draw1() { | |
for(let i = 0; i <= 5; i++){ | |
for(let j = 1; j <= i; j += 1){ | |
document.write(STAR); | |
} | |
document.write(NEW_LINE); | |
} | |
document.write(NEW_LINE); | |
} | |
draw1(); | |
function draw2() { | |
for(let i = 5 ; i >= 1 ; i--){ | |
for(let j = i; j >= 1 ; j -= 1){ | |
document.write(STAR); | |
} | |
document.write(NEW_LINE); | |
} | |
document.write(NEW_LINE); | |
} | |
draw2(); | |
function draw3() { | |
} | |
draw3(); | |
function draw4() { | |
} | |
draw4(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SPACE = ' '; | |
const NEW_LINE = '<br>'; | |
const STAR = '*'; | |
function drawRec1(lvl=1) { | |
for (let l = 0; l < lvl; l++) { | |
document.write(STAR); | |
} | |
document.write(NEW_LINE); | |
if (lvl !== 5) { | |
return drawRec1(++lvl); | |
} | |
} | |
drawRec1(); | |
function draw2() { | |
} | |
draw2(); | |
function draw3() { | |
} | |
draw3(); | |
function draw4() { | |
} | |
draw4(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SPACE = ' '; | |
const NEW_LINE = '<br>'; | |
const STAR = '*'; | |
function draw1() { | |
let stars = ''; | |
for (let n = 0; n < 5; n++) { | |
stars += STAR; | |
document.write(stars, NEW_LINE); | |
} | |
} | |
draw1(); | |
function draw2() { | |
let stars = STAR.repeat(5); | |
for (let n = 0; n < 5; n++) { | |
document.write(stars, NEW_LINE); | |
stars = stars.slice(0, -1) | |
} | |
} | |
draw2(); | |
function draw3() { | |
let stars = STAR.repeat(5); | |
let spaces = ''; | |
for (let n = 0; n < 5; n++) { | |
document.write(spaces, stars, NEW_LINE); | |
stars = stars.slice(0, -1) | |
spaces += SPACE; | |
} | |
} | |
draw3(); | |
function draw4() { | |
let stars = ''; | |
let spaces = SPACE.repeat(4); | |
for (let n = 1; n <= 5; n++) { | |
stars += STAR; | |
document.write(spaces, stars, NEW_LINE); | |
spaces = spaces.slice(0, -SPACE.length); | |
} | |
} | |
draw4(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment