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

Q1 Code

button

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)
18 views2 pages

Q1 Code

button

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
You are on page 1/ 2

<!

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