Search This Blog

Thursday, 28 July 2016

How to repeat the word in two or more times using javascript?

Html Page:

<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

JavaScript page:

<script>
function myFunction()
 {
    var str = "Hello world!";
    document.getElementById("demo").innerHTML = str.repeat(2);
}
</script>

Output:

Hello world! Hello world!

No comments:

Post a Comment