Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <script language="javascript" type "text/javascript">
  2. function initArray(n) {
  3. var arrayLocation = 0;
  4. var numbers = [];
  5.  
  6. for (var x = 1; x <= n; x++) {
  7. numbers[arrayLocation] = Math.floor(Math.random() * 101);
  8. arrayLocation++;
  9. }//end of for
  10. document.write(numbers + "<br/>");
  11. return numbers;
  12. }//end of function initArray
  13.  
  14. function checkIfInArray(n, anArray) {
  15. var x = numbers.length;
  16. var doesContain = 0;
  17.  
  18. for (var x = 0; x > numbers.length; x++) {
  19. if (numbers[x] == n) {
  20. doesContain = 1;
  21. break;
  22. } else {
  23. doesContain = 0;
  24. }//end of else
  25. }//end of for
  26.  
  27. if (doesContain = 0) {
  28. document.write("The array does not contain the number " + n);
  29. } else {
  30. document.write("The array does contain the number " + n);
  31. }//end of else
  32. }//end of function checkIfInArray
  33.  
  34. checkIfInArray(11, initArray(10));
  35.  
  36. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement