author | handle | source | date | likes | retweets | replies |
---|---|---|---|---|---|---|
Ajay Yadav 🎯 |
@ATechAjay |
April 24, 2022 4:01 PM |
149 |
26 |
21 |
Ajay Yadav 🎯 (@ATechAjay) - April 24, 2022 4:01 PM
4️⃣ / 5️⃣0️⃣ The Ultimate JavaScript Projects Series!
🎉 Random Number Generator
A Thread🧵👇 pic.twitter.com/Yt7vi2sE3u
💡 Learning from this project?
📌 Math Object 📌 Random Method 📌 Trunc Method
🛠 It's used when we want to build a ludo/dice game.
→ This is the HTML code for this small project. pic.twitter.com/Nbcm08N9Cv
→ First of all, we have to select these HTML elements using JavaScript. pic.twitter.com/ei8UhuoJbT
→ Now we have to use the random method of the Math function of JavaScript.
📌 Math Object
→ Math object all you to perform the mathematical tasks on numbers.
→ Properties and methods can be called using the Math object.
→ Math object works only with the number data type.
→ The Math object is a built-in object that has some properties and methods for mathematical calculations.
📌 Random Method
→ This is a method of the Math object that is used to generate random numbers.
→ It generates random numbers between 0 and 1 but less than 1. pic.twitter.com/lAF6RVwuBl
→ But if we want to generate in the bigger range then we have to multiple with that max number.
→ Now the number generated will be between 0 to 100 or 0 to 101 but 101 is not included. pic.twitter.com/n9UB0vp9mF
→ But this method generated a number with decimal values that's why we have to remove that fractional numbers.
📌 Trunc Method
→ This is also a method of the Math object that is used to remove fractional digits after the dot.
→ Or, it returns the integer value.
→ Or, its return a value without fractional value.
→ Or, it truncates the digit to the right of the dot in other words it simply removes the fractional digit.
→ This method is newly added in JavaScript(ES6) pic.twitter.com/inkqEQ71wj
→ So finally, we have to implement a click event on this button and change the number on each click.
→ It returns the number between 0 to 100. pic.twitter.com/14BGiYwAiX
👀 Codepen link:
🎉 Congratulation we have successfully completed this small project.
But if you like make sure to:
-
Follow me @ATechAjay
-
Retweet the first tweet.
-
Turn on the notification to never miss these amazing tweets.
Thank you so much for staying to the end of this thread.