Downward Triangle Star Pattern in JavaScript to create a downward triangle star pattern use a nested loops, it's also known as a reverse star patterns. From the above-shown patterns, you can see the numbers of stars decreases from 'n' to 1.
*****
****
***
**
*
Source Code:
// Write Javascript code!
let n = 5;
let string = "";
for (let i = 0; i < n; i++) {
// printing star
for (let k = 0; k < n - i; k++) {
string += "*";
}
string += "\n";
}
document.getElementById('app').innerText = string
//console.log(string);
No comments:
Post a Comment