Skip to content
Advertisements

while loop examples

The program that prints numbers between 0-100

var i = 0;
        while (i < 100) {
            i += 2;
            document.write(i+"<br>")
        }

Growing Writing Program

var i = 10;
        while (i <= 50) {
            i += 10;
            document.write("<p style='font-size:" + i + "px;'>" + "TURKIYE" + "</p>")
        }

The double numbers are blue, the single numbers are yellow

var i = 0;
        while (i <= 100) {
            i++;
            if (i % 2 == 0) {
                document.write("<span style='color:blue;'>" + i + "</span><br/>");
            } else {
                document.write("<span style='color:yellow;'>" + i + "</span><br/>");
            }
        }

Find the even number of program

var answer,
            total = 0;
        while (answer % 2 != 0) {
            answer = prompt("Number:");
        }
        document.write(answer)

Password control

var password = "123",
            life = 3;
        while (life > 0) {
            var message = prompt("password");
            life--;
            if (life == 0) break;
            if (message == password) {
                document.write("welcome");
                break;
            } else {
                alert("life:" + life);
            }
        }
        if (life == 0) {
            document.write("YOU CAN NOT ENTER")
        }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: