Saturday, August 22, 2015

How to looping star from given value

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>star</title>
</head>
<body>
<input type="text" name="" id="given_number"><br><br>
<button onclick="star_looping()">Click</button>
<br><br>
<div id="result"></div>


<script>
    function star_looping() {


        var number = parseInt(document.getElementById('given_number').value);
        var result = "*";
        var star;
        for (var i = 0; i < number; i++) {
            if (star == undefined) {
                star = result + "<br>";
            } else {
                star = star + result + "<br>";
            }
            result = result + "*";
        }
        document.getElementById("result").innerHTML = star;
    }
</script>
</body>
</html>

No comments:

Post a Comment

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }