Skip to content

Latest commit

 

History

History

05 - Random_number_generator

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
author handle source date likes retweets replies
Ajay Yadav 🎯
@ATechAjay
April 24, 2022 4:01 PM
149
26
21

ATechAjay 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

3_1518198381209812992

💡 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

3_1518198388377849858

→ First of all, we have to select these HTML elements using JavaScript. pic.twitter.com/ei8UhuoJbT

3_1518198394321129475

→ 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

3_1518198402806280192

→ 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

3_1518198409487785986

→ 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

3_1518198418434260993

→ 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

3_1518198424675389440

👀 Codepen link:

codepen.io/atechajay/pen/…

🎉 Congratulation we have successfully completed this small project.

But if you like make sure to:

  1. Follow me @ATechAjay

  2. Retweet the first tweet.

  3. Turn on the notification to never miss these amazing tweets.

Thank you so much for staying to the end of this thread.

Thread link