Skip to main content

Featured

Tic Tac Toe

Tic Tac Toe Tic Tac Toe is a simple, two-player strategy game played on a 3x3 grid. Players take turns marking a square with either an "X" or an "O", with the goal of being the first to align three of their marks in a row, column, or diagonal.  I have made a simple Tic Tac Toe game using html, css, javascript.  The game doesnot have much features. The game is created to be played by two peoples. It is just a simple game. The code of this game you get in my github page   Link of this game code is below: Tic Tac Toe Game Code /

Generating Random Number from Javascript

Hello guys, after reading this blog you will know how you can generate a random number through JavaScript

We can generate the random number through Math.random() function but this gives us number in decimal.
So we should write the Math.random()  * 10 inside the Math.floor to get a integer number not a decimal number from 0 to 10 (10 not included); In JavaScript Math is a object that helps you to do mathematical operations. And Math.floor() is a function that round offs the number and return a integer.


We can use different places where we have to make choosing from the computer. For example one array is there, from that array we have to make computer choose a array item.

Here's one code which help you in understanding 

arr = ["Rock", "Papper", "Scissor"]
random_num = Math.floor(Math.random() * arr.length)
alert(arr[random_num])

Comments

Popular Posts