0% found this document useful (0 votes)
22 views2 pages

Q1 Code

The document is an HTML page that prompts the user to input 10 numbers into an array and then allows the user to search for a specific number within that array. It displays the contents of the array and whether the searched number is found or not. The script uses JavaScript to handle user inputs and update the HTML elements accordingly.

Uploaded by

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

Q1 Code

The document is an HTML page that prompts the user to input 10 numbers into an array and then allows the user to search for a specific number within that array. It displays the contents of the array and whether the searched number is found or not. The script uses JavaScript to handle user inputs and update the HTML elements accordingly.

Uploaded by

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

<!

DOCTYPE html>
<html>
<head>
<title>Usama Question 1</title>
</head>
<body>
<div id="output1"></div>
<div id="output2"></div>
<div id="output3"></div>
</body>
</html>

<script type="text/javascript">
let array = [];

alert("Input 10 numbers to store in array");


for (var i = 1; i <= 10; i++) {
array[i] = prompt("Enter number " + i + " in array");
}

alert("Now Enter number to search in your array;");


let inputNumber = prompt("Input Number to search");

let output1 = document.getElementById("output1");

let output2 = document.getElementById("output2");

let output3 = document.getElementById("output3");

let arrayContents =
array[1] +
"," +
array[2] +
"," +
array[3] +
"," +
array[4] +
"," +
array[5] +
"," +
array[6] +
"," +
array[7] +
"," +
array[8] +
"," +
array[9] +
"," +
array[10];

output1.innerHTML = "Contents of array are: " + arrayContents;


output2.innerHTML = "Number input by user is: " + inputNumber;

for (var i = 1; i <= 10; i++) {


if (inputNumber == array[i]) {
output3.innerHTML = "Number is found in array";
break;
} else {
output3.innerHTML = "Number is not found in array";
}
}
</script>

You might also like