Question

Write a JavaScript program that will do the following: Create an array of size 50. Store...

Write a JavaScript program that will do the following:

  • Create an array of size 50.
  • Store randomly generated number (between 0 and 10) into this array.
  • Ask users what number they want to search in the array. Make sure user given number is between 0 and 10.
  • Search the user given number in the array:
    • If the program found the number in the array then display all the indexes where the number was found.
    • If the program does not find the number in the array then give an appropriate message e.g. “number not found!”
  • Write a function to solve this problem.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

<!DOCTYPE html>
<html>
<body>
<script>
var arr = new Array(50);
for(i=0;i<50;i++)
   arr[i]=Math.floor(Math.random() * 11);
n = prompt("Please enter the number between 1-10 to search");
var message="";
for(i=0;i<50;i++)
   if(arr[i]==n)
       message=message+" "+i;
if(message.length!=0)
   alert("Found at : "+message);
else
   alert(n+" Does not exist ");
</script>

</body>
</html>

Input:

Output:

Add a comment
Know the answer?
Add Answer to:
Write a JavaScript program that will do the following: Create an array of size 50. Store...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT