<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>star looping</title>
</head>
<body>
<input type="text" name="" id="number">
<button onclick="star_looping()">Click to loop</button>
<br>
<div id="result"></div>
<script>
function star_looping(){
var number = parseInt(document.getElementById('number').value);
var star = "";
for (var i = 0; i <= number; i++){
for (var j = 0; j < i; j++){
star = star + "* ";
}
star = star + "<br>";
}
for(var i = number-1; i > 0; i--){
for (var j = 0; j < i; j++){
star = star + "* ";
}
star = star + "<br>";
}
document.getElementById('result').innerHTML = star;
}
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>star looping</title>
</head>
<body>
<input type="text" name="" id="number">
<button onclick="star_looping()">Click to loop</button>
<br>
<div id="result"></div>
<script>
function star_looping(){
var number = parseInt(document.getElementById('number').value);
var star = "";
for (var i = 0; i <= number; i++){
for (var j = 0; j < i; j++){
star = star + "* ";
}
star = star + "<br>";
}
for(var i = number-1; i > 0; i--){
for (var j = 0; j < i; j++){
star = star + "* ";
}
star = star + "<br>";
}
document.getElementById('result').innerHTML = star;
}
</script>
</body>
</html>
No comments:
Post a Comment