Question:

How to repeat javascript code?

by  |  earlier

0 LIKES UnLike

I have an alert() and a prompt() in variables how can i make them repeat?

 Tags:

   Report

1 ANSWERS


  1. You need a loop.  If you want them to repeat a specific number of times, you would generally use a for loop.  If you want them to repeat until a specific condition is true or false, you generally use a while loop.  If you want them to repeat forever (why?) you can achieve this with either.

    Here are examples:

    // to repeat 3 times

    for (var i = 0; i < 3; i++) {

      alert('Hello world!');

    }

    // to repeat endlessly

    // I recommend you don't run this; it'll not be a pleasant experience!

    while (true) {

      alert('Hello world!');

    }

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.