Guest User

Untitled

a guest
Feb 17th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. //Create array
  2. const arr = [];
  3. for(let i = 0;i < 10;i++){
  4. //Fill array with random values between 1 and 50
  5. arr.push(Math.floor(Math.random() * 50) + 1)
  6. }
  7. //Display array
  8. console.log(arr)
  9. //Prompt user for input
  10. const num = prompt('Enter number')
  11. //Filter array to include only numbers that match input
  12. const times = arr.filter(e => e === parseInt(num))
  13. //Print number of times
  14. console.log(`${times.length} times`)
  15.  
  16. //It's not foolproof you can add check to confirm input is a number and all but it solves the basic problem
Add Comment
Please, Sign In to add comment