Quantcast
Channel: User easement - Stack Overflow
Viewing all articles
Browse latest Browse all 45

Answer by easement for Removing an already picked phrase from an array

$
0
0

Something along these lines should work. Below is my attempt at putting your code back in:

var allShows = ['Bones', 'Psych', 'Big Bang Theory', 'Mad Men', 'Breaking Bad', 'Modern Family', 'Game of Thrones', 'Dexter'];var currentShow = allShows[0]; //Just to initialize // Filter out the one you have selectedfunction getAvailableShows() {  return allShows.filter(function(e) { return e !== currentShow })}function playClicked() {  // make a pool - current one playing  var availableShows = getAvailableShows();   // choose one from random  var show = availableShows[Math.floor(Math.random() * availableShows.length)];   // update current show  currentShow = show;  // updae text  this.tekst.text = show;}this.knapp.addEventListener("click", playClicked.bind(this));

Here's a code pen showing that it works via console log. https://codepen.io/easement/pen/MbNwdw


Viewing all articles
Browse latest Browse all 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>