Row and column javascript/Jquery

Asked

Viewed 35 times

0

I need a pure or jquery script that runs a row and column structure. Example, if the user type 7 I have to print the following structure:

x
xx
xxx
xxxx
xxxxx
xxxxxx
xxxxxxx

I tried to use for but only runs the line.

1 answer

1


There are several ways to do this. When you say print, I will use the console to show the result.

var numero = 7; // Número inserido pelo usuário.
var caracter = 'x'; // Caracter que deseja imprimir.
var resultado = ''; // Variável para armazenar o resultado e imprimir.

for(i = 0; i < numero; i++){
    resultado = resultado + caracter;
    console.log(resultado);
}

This will result in the console:

x
xx
xxx
xxxx
xxxxx
xxxxxx
xxxxxxx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.