While loops in JavaScript - example 1

by danielkwood

HTML

<html>
    <head>
        <title>While loops</title>
        <script src="script.js"></script>
    </head>
        
    <body>

    </body>
</html>

JavaScript

// Set the counter to 1
var counter = 1;

// Keep counting up by 1 until the counter reaches 10
while(counter <= 10){
    console.log(counter);
    counter++;
}

console.log("Goodbye!");