Hi , welcome to new JavaScript practice project "Random Emoji" for beginners along with explaination. You can copy the code by clicking the button just above the code. Read the explaiantion for better understanding.
let's get started with index.html file:
index.html
style.css:
index.js:
Here is the explaination:
Fetching Emojis:
It defines an empty array emoji to store the fetched emojis.
The getEmoji() function is an asynchronous function that fetches emojis using the Emoji API.
It makes a GET request to the specified API endpoint and retrieves the response data.
The response data is an array of emoji objects.
The function loops through the data and extracts the emoji's name and Unicode code, then adds them to the emoji array.
Generating and Displaying Random Emoji:
It selects the HTML elements with IDs btn and emoji-name.
It adds an event listener to the button with the btn ID, which triggers a function when the button is clicked.
When the button is clicked, a random number is generated within the range of the emoji array's length.
The button's inner text is updated with the selected emoji's name, and the emoji-name element's inner text is updated with the selected emoji's Unicode code.
Additionally, there is another part of the code that displays animated text saying "Generate random emoji" in the container element. The updateText() function increments the characterIndex and extracts a substring of the text based on the characterIndex value. The container's HTML is then updated with the animated text. The function is called recursively using setTimeout() to create the animation effect.
FINAL WORDS:
Thank you Don't forget to leave your feedback in the comment section. Follow front.end24 on instagram for more project ideas
index.html
style.css:
index.js:
Here is the explaination:
Fetching Emojis:
It defines an empty array emoji to store the fetched emojis.
The getEmoji() function is an asynchronous function that fetches emojis using the Emoji API.
It makes a GET request to the specified API endpoint and retrieves the response data.
The response data is an array of emoji objects.
The function loops through the data and extracts the emoji's name and Unicode code, then adds them to the emoji array.
Generating and Displaying Random Emoji:
It selects the HTML elements with IDs btn and emoji-name.
It adds an event listener to the button with the btn ID, which triggers a function when the button is clicked.
When the button is clicked, a random number is generated within the range of the emoji array's length.
The button's inner text is updated with the selected emoji's name, and the emoji-name element's inner text is updated with the selected emoji's Unicode code.
Additionally, there is another part of the code that displays animated text saying "Generate random emoji" in the container element. The updateText() function increments the characterIndex and extracts a substring of the text based on the characterIndex value. The container's HTML is then updated with the animated text. The function is called recursively using setTimeout() to create the animation effect.
FINAL WORDS:
Thank you Don't forget to leave your feedback in the comment section. Follow front.end24 on instagram for more project ideas

Comments
Post a Comment