0

So this below is my simple code and i need to display something like ['codigo','codigo']

qtderepeticoes = 3
variavelrepetidora = 'codigo'

function repetition(variavelrepetidora, qtderepeticoes) {
  let resultado = []

  for (let i = 0; i < qtderepeticoes; i++)
    resultado.push(variavelrepetidora)

  return resultado
}

console.log(repetition())

What shoud i write to the 'console.log' to show my array?

3 Answers 3

2

You forgot to pass arguments:

repetition(variavelrepetidora, qtderepeticoes )

const qtderepeticoes = 3
const variavelrepetidora = 'codigo'

function repetition(variavelrepetidora, qtderepeticoes) {

  let resultado = []

  for (let i = 0; i < qtderepeticoes; i++)
    resultado.push(variavelrepetidora)

  return resultado
}


console.log(repetition(variavelrepetidora, qtderepeticoes))

Sign up to request clarification or add additional context in comments.

5 Comments

That's what we call a "typo question". There is no need to answer these types of questions because they are "unlikely to help others with the same problem".
@CristianoPereiradaSilva usually people spend few days on trying to fix the issue themself before asking on stackoverflow
@HereticMonkey it's usually really hard to find anything on StackOverflow, built-in search is really bad, using site:stackoverflow.com in google helps a little, but not so much. My process of finding solutions for my problems here is to google my problems in different words until I find something. Closed questions are harder sadly.
So....how would someone find this question? They would have to have written a function that takes arguments and not passed those arguments in, all the while, expecting an array to show up in a console.log. And they'd have to search for something about logging an array, not about taking arguments. This is a helpdesk question, not something Stack Overflow was built for. It's not meant to have every question about every possible error anyone could ever make when programming.
There are 2,5 million questions with javascript tag right now, I guess we can make an answer to every question ever asked with these numbers.
0

Call your function with 2 arguments, and store the result in a variable result:

var result = repetition(arg1, arg2);

Console the output:

console.log(result);

Comments

0

if you want default values for your function so you don't have to pass any args;

function repetition(variavelrepetidora='codigo', qtderepeticoes=3) {

  const resultado = [];

  for (let i = 0; i < qtderepeticoes; i++)
    resultado.push(variavelrepetidora);

  return resultado;
}

console.log(repetition())

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.