Making a random choice picker

Today I learned how to create a simple random choice picker. A user types in multiple choices separated by a comma and the application randomly selects one of the choice. This project taught me

  • Using a math function to create a random selection.
  • Adding a class list and inserting HTML tags programmatically
  • Using the filter method along with other methods
function createTags(input){ const tags = input.split(',') .filter(tag => tag.trim()!== '') .map(tag => tag.trim()) tagsEl.innerHTML = ''; tags.forEach(tag => { const tagEl = document.createElement('span'); tagEl.classList.add('tag'); tagEl.innerText = tag; tagsEl.appendChild(tagEl); }) }

File Info

Category HTML / JS / CSS
Credits 50 Projects in 50 days
Date January 30th, 2025
Codepen Click here