settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Triangle of Dollars - JavaScript task

+2 votes

Write a JS function that prints a triangle of n lines of “$” characters like shown in the examples.

The input comes as a single number n (0 < n < 100).

Examples:

Input:
3

Output:
$
$$
$$$


Input:
2

Output:
$
$$


Input:
4

Output:
$
$$
$$$
$$$$

The output consists of n text lines like shown above.

asked in JavaScript category by user richard8502

1 Answer

+1 vote

Here is the dollars triangle:

function printTriangle(row) {
    let line = "";
    for (let col = 1; col <= row; col++) {
        line += "$";
        console.log(line);
    }
}

printTriangle(4);

 

answered by user nikole
...