0% found this document useful (0 votes)
37 views

Web Programming Task Performance

The document provides examples of using if and if/else statements to: 1) confirm a user's age or number input; and 2) print lists of numbers that meet certain criteria. Conditional logic and loops are used to check conditions and iterate through numbers.

Uploaded by

yvonnekim1432
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Web Programming Task Performance

The document provides examples of using if and if/else statements to: 1) confirm a user's age or number input; and 2) print lists of numbers that meet certain criteria. Conditional logic and loops are used to check conditions and iterate through numbers.

Uploaded by

yvonnekim1432
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Web Programming Task Performance

1. Construct if and if… else statements that meet the following:

a.) Display a dialog box confirming a user is 25 years old and up.

<!DOCTYPE html>
<html>
<head>
<title>Age Confirmation</title>
</head>
<body>

<script>
function checkAge() {
var age = prompt("Please enter your age:");
if (age >= 25) {
alert("You are 25 years old or older.");
} else {
alert("You are under 25 years old.");
}
}
</script>

<button onclick="checkAge()">Check Age</button>

</body>
</html>

b.) Display a dialog box confirming a user entered a number less than 100.

<!DOCTYPE html>
<html>
<head>
<title>Number Confirmation</title>
</head>
<body>

<script>
function checkNumber() {
var userInput = prompt("Please enter a number:");
var number = parseFloat(userInput);

if (!isNaN(number) && number < 100) {


alert("You entered a number less than 100.");
} else {
alert("You either didn't enter a valid number or entered a number greater
than or equal to 100.");
}
}
</script>

<button onclick="checkNumber()">Check Number</button>

</body>
</html>

2. Construct if and if else statements that meet the following:

a.) Print the numbers 0-30, one number per line.

<!DOCTYPE html>
<html>
<head>
<title>Number List</title>
</head>
<body>

<h2>Numbers from 0 to 30:</h2>


<ul id="numberList"></ul>

<script>
for (var i = 0; i <= 30; i++) {
var listItem = document.createElement('li');
listItem.textContent = i;
document.getElementById('numberList').appendChild(listItem);
}
</script>

</body>
</html>
b.) Print only the even values from 0-40, one number per line.

<!DOCTYPE html>
<html>
<head>
<title>Even Numbers</title>
</head>
<body>

<h2>Even Numbers from 0 to 40:</h2>


<ul id="evenNumberList"></ul>

<script>
var evenList = document.getElementById('evenNumberList');
for (var i = 0; i <= 40; i += 2) {
var listItem = document.createElement('li');
listItem.textContent = i;
evenList.appendChild(listItem);
}
</script>

</body>
</html>

c.) Print the numbers 40 to 10 in descending order, but only if the numbers are multiples of 3.

<!DOCTYPE html>
<html>
<head>
<title>Multiples of 3</title>
</head>
<body>

<h2>Multiples of 3 from 40 to 10:</h2>


<ul id="multipleOf3List"></ul>

<script>
var multipleOf3List = document.getElementById('multipleOf3List');

for (var i = 40; i >= 10; i--) {


if (i % 3 === 0) {
var listItem = document.createElement('li');
listItem.textContent = i;
multipleOf3List.appendChild(listItem);
}
}
</script>

</body>
</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy