Lacos while in javascript

1

I need to create a while loop that I sent a message x number of times to the console.

var loop = function(){
    while(){
        console.log("");
    }
}

loop(); 
    
asked by anonymous 29.09.2016 / 21:30

1 answer

3

Just create a condition:

var loop = function(x) {
  qtd = 0;
  while (qtd < x) {
    console.log("Mensagem #" + qtd);
    qtd++;
  }
}

loop(10);
    
29.09.2016 / 21:36