0% found this document useful (0 votes)
7 views1 page

Array

The document contains a JavaScript code that initializes an array with 10 elements and prompts the user to enter names for each element. If the user provides no input, a default message is stored instead. Finally, it displays the entered names in a structured list format on the webpage.

Uploaded by

srinimaha1442005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Array

The document contains a JavaScript code that initializes an array with 10 elements and prompts the user to enter names for each element. If the user provides no input, a default message is stored instead. Finally, it displays the entered names in a structured list format on the webpage.

Uploaded by

srinimaha1442005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

<html>

<head>
<title>To create an array of 10 elements and display its contents</title>
</head>
<body>
<script type="text/javascript">
var a = new Array(10); // Initialize an array with 10 elements

// Asking for input only once


alert("Please enter 10 names.");

// Collecting names through prompt


for (let i = 0; i < [Link]; i++) {
let name = prompt("Enter value for element " + (i + 1) + ":");

// Check if the input is empty


if (name === null || [Link]() === "") {
a[i] = "No input provided"; // default message for empty input
} else {
a[i] = [Link](); // Store the entered value
}
}

// Displaying values with more structured output


[Link]("<h3><b>Given values are:</b></h3>");
[Link]("<ul>");
for (let i = 0; i < [Link]; i++) {
[Link]("<li>" + a[i] + "</li>");
}
[Link]("</ul>");
</script>
</body>
</html>

You might also like