Untitled

 avatar
unknown
plain_text
23 days ago
1.0 kB
3
Indexable
<!DOCTYPE html>
<html>
<head>
  <title>Loops and Conditions</title>
</head>
<body>
  <h2>Check User Age</h2>
  <script>
    // Task 1a
    let age = prompt("Enter your age:");
    if (age >= 25) {
      alert("User is 25 years old and up.");
    }

    // Task 1b
    let number = prompt("Enter a number:");
    if (number < 100) {
      alert("User entered a number less than 100.");
    }

    document.write("<h2>For Loop Tasks</h2>");

    // Task 2a
    document.write("<p>Numbers from 0 to 30:</p>");
    for (let i = 0; i <= 30; i++) {
      document.write(i + "<br>");
    }

    // Task 2b
    document.write("<p>Even numbers from 0 to 40:</p>");
    for (let i = 0; i <= 40; i++) {
      if (i % 2 === 0) {
        document.write(i + "<br>");
      }
    }

    // Task 2c
    document.write("<p>Multiples of 3 from 40 to 10 in descending order:</p>");
    for (let i = 40; i >= 10; i--) {
      if (i % 3 === 0) {
        document.write(i + "<br>");
      }
    }
  </script>
</body>
</html>
Editor is loading...
Leave a Comment