Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create array
- const arr = [];
- for(let i = 0;i < 10;i++){
- //Fill array with random values between 1 and 50
- arr.push(Math.floor(Math.random() * 50) + 1)
- }
- //Display array
- console.log(arr)
- //Prompt user for input
- const num = prompt('Enter number')
- //Filter array to include only numbers that match input
- const times = arr.filter(e => e === parseInt(num))
- //Print number of times
- console.log(`${times.length} times`)
- //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