$(document).ready(function() {
  const CLIENT_ID = '<%= ENV['CLIENT_ID'] %>';

  axios.get(`https://api.soundcloud.com/users/14533601/tracks?client_id=${CLIENT_ID}`)
    .then(function (response) {
      // Store the length of the tracks
      const trackLength = response.data.length;

      // Pick a random number
      const randomNumber = Math.floor((Math.random() * trackLength) + 1);

      // Return track id of random track
      track = response.data[randomNumber]
      console.log(track)
      trackId = response.data[randomNumber].id
      trackName = response.data[randomNumber].title
      trackUrl = response.data[randomNumber].permalink_url
    })
    .then(function() {
      SC.initialize({
        client_id: '<%= ENV['CLIENT_ID'] %>'
      });

      SC.stream('/tracks/' + trackId, function(sound) {
        let playing = false;

        $('.track-name').html(trackName)

        $('.radio').on('click', '#start', function(event) {
          event.preventDefault();
          if (playing === true) {
            sound.pause();
            playing = false;
          } else {
            sound.play()
            playing = true;
          }
        });

        $('.radio').on('click', '#stop', function(event) {
          event.preventDefault();
          sound.pause();
          playing = false;
        });
      });
    })
});

$(document).ready(function() {
  const CLIENT_ID = '<%= ENV['CLIENT_ID'] %>';

  axios.get(`https://api.soundcloud.com/users/14533601/tracks?client_id=${CLIENT_ID}`)
    .then(function (response) {
      // Store the length of the tracks
      const trackLength = response.data.length;

      // Pick a random number
      const randomNumber = Math.floor((Math.random() * trackLength) + 1);

      // Return track id of random track
      track = response.data[randomNumber]
      console.log(track)
      trackId = response.data[randomNumber].id
      trackName = response.data[randomNumber].title
      trackUrl = response.data[randomNumber].permalink_url
    })
    .then(function() {
      SC.initialize({
        client_id: '<%= ENV['CLIENT_ID'] %>'
      });

      SC.stream('/tracks/' + trackId, function(sound) {
        let playing = false;

        $('.track-name').html(trackName);
        $('.track-name').attr('href', trackUrl);

        $('.radio').on('click', '#start', function(event) {
          event.preventDefault();
          if (playing === true) {
            sound.pause();
            playing = false;
          } else {
            sound.play()
            playing = true;
          }
        });

        $('.radio').on('click', '#stop', function(event) {
          event.preventDefault();
          sound.pause();
          playing = false;
        });
      });
    })
});

Update radio to include url for playing track
Update radio to include url for playing track
