Nested Loops

Developer
Size
2,231 Kb
Views
60,720

How do I make an nested loops?

Https://www.reddit.com/r/javaScriptStudyGroup/. What is a nested loops? How do you make a nested loops? This script and codes were developed by Steven on 31 July 2022, Sunday.

Nested Loops Previews

Nested Loops - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Nested Loops</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="debug" class="debug"></div> <script src="js/index.js"></script>
</body>
</html>

Nested Loops - Script Codes CSS Codes

body { background: rgba(0, 100, 200, .5); font-family: "Lucida Console", Monaco, monospace
}
.debug { background: rgba(0, 100, 200, .5); font-size:30px; border: solid black 5px; color: white; width:80vw; margin:10px auto; padding: 5px;
}

Nested Loops - Script Codes JS Codes

var volv$ = function (x) { return document.getElementById(x); };
var css = "color:blue; font-size: 2.5vh";
function outFunc(str) { console.log("%c" +str, css); volv$("debug").innerHTML += str.replace(/\s/g, "&nbsp;") + "<br>";
}
function makeTriangle1(lines, callback) { for (var i=1; i<=lines; i++) { var result = ""; for (var j=1; j<=lines; j++) { result += (j<=lines-i) ? " " : i; } callback(result); }
}
outFunc("//makeTriangle1(6)");
makeTriangle1(6, outFunc);
function makeTriangle2(lines, callback) { for (var i=1; i<=lines; i++) { var result = ""; for (var j=1; j<=lines-i; j++) { result += " "; } for (var j=1; j<=i*2-1; j++) { result += i.toString(); } callback(result); }
}
outFunc("");
outFunc("//makeTriangle2(3)");
makeTriangle2(3, outFunc);
function makeTriangle3(lines, callback) { lines = (lines % 2 === 0) ? lines+1 : lines; //Use next odd number if not odd var half = Math.floor(lines/2) + 1; for (var i=1; i<=lines; i++) { var result = ""; if (i < half) { for (var j=half; j > i; j--) { result += " "; } for (var j=0; j < i; j++) { result += i; } } if (i === half) { for (var j=0; j < i; j++) { result += i; } } if (i > half) { for (var j=half; j < i; j++) { result += " "; } for (var j=i; j <= lines; j++) { result += i; } } callback(result); }
}
outFunc("");
outFunc("//makeTriangle3(6)");
makeTriangle3(6, outFunc);
// String.repeat() ftw
// function makeTriangle2(lines) {
// for (var i=1; i<=lines; i++) {
// var result = "";
// result += " ".repeat(lines-i);
// result += i.toString().repeat(i*2-1);
// console.log("%c" +result, css);
// }
// }
Nested Loops - Script Codes
Nested Loops - Script Codes
Home Page Home
Developer Steven
Username volv
Uploaded July 31, 2022
Rating 3
Size 2,231 Kb
Views 60,720
Do you need developer help for Nested Loops?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Steven (volv) Script Codes
Create amazing sales emails with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!