Laman

Javascript Perulangan dan Segitiga

 <script type="text/javascript" charset="utf-8">
    document.write("- Segitiga 1<br>");
    for (var i=1;i<=5;i++){
        for (var j=1;j<=i;j++){
            document.write("*");
        }
        document.write("<br>");
    }
    document.write("- Segitiga 2<br>");
    for (var i=1;i<=5;i++){
        for (var j=i;j<=5;j++){
            document.write("*");
        }
        document.write("<br>");
    }
    document.write("- Segitiga 3<br>");
    for (var i=1;i<=5;i++){
        for (var j=i;j<=5;j++){
            document.write("_");
        }
        for (var k=1;k<=i;k++){
            document.write("*");
        }
        document.write("<br>");
    }
    document.write("- Segitiga 4<br>");
    for (var i=1;i<=5;i++){
        for (var j=1;j<=i;j++){
            document.write("_");
        }
        for (var k=i;k<=5;k++){
            document.write("*");
        }
        document.write("<br>");
    }
 
   
document.write("- Piramida 1<br>");
    for (var i=1;i<=5;i++){
        for (var j=i;j<=5;j++){
            document.write("_");
        }
        for (var k=1;k<=i;k++){
            document.write("*");
        }
        for (var l=1;l<=i-1;l++){
            document.write("*");
        }
        document.write("<br>");
    }
    document.write("- Piramida 2<br>");
    for (var i=1;i<=5;i++){
        for (var j=1;j<=i;j++){
            document.write("_");
        }
        for (var k=i;k<=5;k++){
            document.write("*");
        }
        for (var l=i+1;l<=5;l++){
            document.write("*");
        }
        document.write("<br>");
    }
</script>

No comments:

Post a Comment

Silahkan