Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
Generate random using button using JavaScript

How can I get a button to generate a random emoji (from a list of emojis) every time it is clicked using JavaScript.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to store your emojis as their hex values, not as their HTML entity encoded form. Also, it seems the Unicode values you picked map to Japanese characters, not emojis. Here's a working (except for actually using Japanese characters) script that I cleaned up a bit:

var emojis = [0x128512, 0x128516, 0x128513, 0x128514];
var display = document.getElementById('emojiDisplay');

function displayEmoji(){
  var random = Math.floor(Math.random() * emojis.length);
  var emoji = emojis[random];         
  display.innerHTML=`<h2>${String.fromCharCode(emoji)}</h2>`;
}
about 4 years ago · Juan Pablo Isaza Report

0

You are replacing the emoji list in the funcition

var emojiList = ['&#128512', '&#128516', '&#128513', '&#128514'];
var display = document.getElementById('emojiDisplay');

function displayEmoji() {

 
  let randomEmojiIndex = Math.floor(Math.random() * emojiList.length);
  emoji = emojiList[randomEmojiIndex];
  
  display.innerHTML = `<h2>${emoji}</h2>`;

}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!