Sunday, June 25, 2023

JavaScript For Loop

 

JavaScript Loops

Loops are handy, if you want to run the same code over and over again, each time with a different value.

Often this is the case when working with arrays:

Example

<!DOCTYPE html>

<html>

<body>


<h2>JavaScript For Loop</h2>


<p id="demo"></p>


<script>

const cars = ["BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi"];


let text = "";

for (let i = 0; i < cars.length; i++) {

  text += cars[i] + "<br>";

}


document.getElementById("demo").innerHTML = text;

</script>


</body>

</html>


No comments:

Post a Comment

JavaScript Animated

  JavaScript Animated <!DOCTYPE html> <html> <style> #myContainer {   width: 400px;   height: 400px;   position: relative;...